-
-
Save nocodesupplyco/3bb881a611ba0094d8f53fef2856ce90 to your computer and use it in GitHub Desktop.
Toggle Accordion Attributes for Accessibility
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
$(".accordion-trigger").click(function () { | |
$(this).toggleAttrVal("aria-expanded", "false", "true"); //toggle trigger attribute | |
$(this) | |
.siblings(".accordion-content") | |
.toggleAttrVal("aria-hidden", "true", "false"); //toggle content attribute | |
}); | |
// jquery toggle just the attribute value | |
$.fn.toggleAttrVal = function (attr, val1, val2) { | |
var test = $(this).attr(attr); | |
if (test === val1) { | |
$(this).attr(attr, val2); | |
return this; | |
} | |
if (test === val2) { | |
$(this).attr(attr, val1); | |
return this; | |
} | |
// default to val1 if neither | |
$(this).attr(attr, val1); | |
return this; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment