Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aboutaaron/6916c539db4ee9f66d51 to your computer and use it in GitHub Desktop.
Save aboutaaron/6916c539db4ee9f66d51 to your computer and use it in GitHub Desktop.
/*!
* toggleAttr() jQuery plugin
* @link https://gist.github.com/aboutaaron/6916c539db4ee9f66d51
* @description .toggleClass() but for attrs. Useful for toggling classes with SVGs or anything that's not a class
* @author Aaron Williams <http://aboutaaron.com/>
* @thanks: Mathias Bynens <http://mathiasbynens.be/> for original
*/
jQuery.fn.toggleAttr = function(attr, value) {
return this.each(function() {
var $this = $(this);
$this.attr(attr) ? $this.removeAttr(attr) : $this.attr(attr, value);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment