Last active
April 22, 2016 06:28
-
-
Save joe-watkins/00a1bd83fec29048f4ed to your computer and use it in GitHub Desktop.
toggleAria.js - a small plugin for swapping boolean aria attributes easier
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
/*! | |
* toggleAria.js | |
* Author: Joe Watkins | |
* usage: | |
HTML | |
<button aria-pressed="false">Show Content</button> | |
$("button").on("click", function(){ | |
$(this).toggleAria({aria: "pressed"}); | |
}); | |
* | |
*/ | |
(function($){ | |
$.fn.toggleAria = function(options) { | |
var defaults = { | |
wrapper: this, | |
aria: "" | |
}, | |
options = $.extend(defaults, options), | |
o = options, | |
currentState = $(o.wrapper).attr("aria-"+o.aria), | |
newState; | |
if(currentState == "false"){ | |
newState = "true"; | |
}else{ | |
newState = "false"; | |
} | |
$(o.wrapper).attr("aria-"+o.aria,newState); | |
}; // $.fn | |
}(jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment