Created
May 21, 2011 14:40
-
-
Save Xodarap/984574 to your computer and use it in GitHub Desktop.
jQuery toggle attribute
This file contains 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
(function ($) { | |
$.fn.toggleAttr = function (attr, val1, val2) { | |
///<summary>Toggles an attribute between having one of two possible states</summary> | |
///<param name="attr">Attribute name</param> | |
///<param name="val1">First value</param> | |
///<param name="val2">Second value</param> | |
return this.each(function () { | |
var $this = $(this); | |
if ($this.attr(attr) === val1) { | |
$this.attr(attr, val2); | |
} else { | |
$this.attr(attr, val1); | |
} | |
}); | |
}; | |
} | |
)(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment