Skip to content

Instantly share code, notes, and snippets.

@Ajnasz
Created Mar 1, 2010
Embed
What would you like to do?
YUI 2 toggleClass
YAHOO.util.Dom.toggleClass = function(el, cn) {
return YAHOO.util.Dom.hasClass(el, cn) ? YAHOO.util.Dom.removeClass(el, cn) : YAHOO.util.Dom.addClass(el, cn);
};
YAHOO.util.Element.prototype.toggleClass = function(cn) {
return YAHOO.util.Dom.toggleClass(this.get('element'), cn);
};
YAHOO.util.Dom.toggleClass('elementid', 'hidden');
// or
var el = new YAHOO.util.Element('elementid');
el.toggleClass('hidden');
.hidden {
display:none;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment