Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jackmakesthings/0af0ebc2140ea2de353a to your computer and use it in GitHub Desktop.
Save jackmakesthings/0af0ebc2140ea2de353a to your computer and use it in GitHub Desktop.
/*!
* 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