Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
toggleAria.js - a small plugin for swapping boolean aria attributes easier
/*!
* 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
You can’t perform that action at this time.