Skip to content

Instantly share code, notes, and snippets.

Created Mar 1, 2010
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');
.hidden {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment