Q:

Toggling className doesn't work

I am trying to make a toggle switch on JavaScript that changes the class of a div when another div is clicked.
Here is my code:
function toggleStart() {    
    var startToggle = document.getElementById('menustart').className;
    if (startToggle == "startmenu") {
        startToggle = 'startclick';
    } else {
        startToggle = 'startmenu';
    }
}

I basically want to add this function to the onclick property of a div. Am I doing something wrong?

A:

I suppose you are struck with reassigning the class.
You are just changing the value of startToggle and not the value of element directly. For that you'll have to reassign the class name to the element for it take effect.
Add this line of code after else block:
document.getElementById('menustart').className = startToggle;

