Created
September 12, 2013 18:58
-
-
Save netsuite/6542267 to your computer and use it in GitHub Desktop.
jquery: toggle attr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery.fn.toggleAttr = function(a, b) { | |
var c = (b === undefined); | |
return this.each(function() { | |
if((c && !jQuery(this).is("["+a+"]")) || (!c && b)) jQuery(this).attr(a,a); | |
else jQuery(this).removeAttr(a); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment