instance method Element#toggleClassName

View source on GitHub →

Element#toggleClassName(className[, bool]) → Element

Toggles the presence of CSS class className on element.

By default, toggleClassName will flip to the opposite state, but will use bool instead if it's given; true will add the class name and false will remove it.

<div id="mutsu" class="apple"></div>


// -> false
// -> Element
// -> true
 $('mutsu').toggleClassName('fruit', true);
// -> Element (keeps the "fruit" class name that was already there)

This method can be called either as an instance method or as a generic method. If calling as a generic, pass the instance in as the first argument.