Building a tree menu with jQuery, and I want it to be accessible, so I'm using aria attributes. What I want to do is toggle the "aria-expanded" attribute from true to false on click/enter. I've tried this, but it's obviously not correct:
$(this).closest('ul').find('> li.tree-parent').toggleAttr( 'aria-expanded', 'true false' );
You can use .attr() to manually write the toggle logic
$(this).closest('ul').find('> li.tree-parent').attr('aria-expanded', function (i, attr) {
return attr == 'true' ? 'false' : 'true'
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With