Skip to content

Instantly share code, notes, and snippets.

@kadimi
Forked from mathiasbynens/toggleAttr() jQuery plugin
Last active August 7, 2023 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kadimi/11067674 to your computer and use it in GitHub Desktop.
Save kadimi/11067674 to your computer and use it in GitHub Desktop.
Toggle checked, selected, disabled, checked, readonly, multiple, etc…
/**
* toggleAttr() jQuery Plugin
*
* Toggle checked, selected, disabled, checked, readonly, multiple, etc…
*/
jQuery.fn.toggleAttr = function (attr) {
return this.each(function () {
var $this = $(this);
if ($this.attr(attr)) {
$this.removeAttr(attr);
} else {
$this.attr(attr, attr);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment