class method Element.toggleClassName
Element.toggleClassName(element, 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.
Examples
<div id="mutsu" class="apple"></div>
Then:
$('mutsu').hasClassName('fruit'); // -> false $('mutsu').toggleClassName('fruit'); // -> Element $('mutsu').hasClassName('fruit'); // -> 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.