In your if statements you aren't comparing (==) classNames but instead assigning (=) values onto them.
Here's the function as you intended it.
Code:
function description(element){
if (element.className=='description_open'){
element.className='description';
}
if (element.className=='description') {
element.className='description_open';
} else {
element.className='description';
}
}
Those not interested in js stop reading now.
What happened in the original function is that in each if statement a new value was assigned to the className (which isn't a failing action, hence the if is handled as being 'true'), so in reality the method just assigned another value to the className 4 times. It could never assign the "description" value because of this.
|