jQuery data-drawer-trigger onclick

Viewed 267

How do I open this data drawer when I assigned it to another button on click event? I've tried to change the attribute but it's not working. Check the jsfiddle please.

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

JSFiddle : https://jsfiddle.net/mhasan09/9mrbq7g0/2/

1 Answers

You'll need to add the following attributes to your new button, like so:

<button data-drawer-trigger aria-controls="drawer-name" >
  Another Button
</button>

If you want to set in the JavaScript you can just use:

let button = document.getElementById("new_button");
button.setAttribute("data-drawer-trigger", true);
button.setAttribute("aria-controls", "drawer-name");

and give an id to the button, like so:

<button id="new_button" >
  Another Button
</button>
Related