I have an accordion with some text marked "Important". I want the page to automatically open pages marked "Important" by clicking a button toggle when the page loads.
I've used $(".diff__filename:contains('sections/')"))
to search for the word "Important" in the title, but I don't know how to tell it to click the button next to it .
I chose to use JQuery to avoid looping through class names.
<p class="title"> Important: Content 1 <button class="toggle">Open</button> </p> <p class="title"> Content 2 <button class="toggle">Open</button> </p> <p class="title"> Content 3 <button class="toggle">Open</button> </p> <p class="title"> Important: Content 4 <button class="toggle">Open</button> </p>
You can use
:contains
on an element and then trigger a click:Load output: