How to use Jquery how to change the aria-expanded="false" part of a dom element (Bootstrap)? How to use Jquery how to change the aria-expanded="false" part of a dom element (Bootstrap)? jquery jquery

How to use Jquery how to change the aria-expanded="false" part of a dom element (Bootstrap)?


You can use .attr() as a part of however you plan to toggle it:

$("button").attr("aria-expanded","true");


Since the question asked for either jQuery or vanilla JS, here's an answer with vanilla JS.

I've added some CSS to the demo below to change the button's font color to red when its aria-expanded is set to true

const button = document.querySelector('button');button.addEventListener('click', () => {  button.ariaExpanded = !JSON.parse(button.ariaExpanded);})
button[aria-expanded="true"] {  color: red;}
<button type="button" aria-expanded="false">Click me!</button>