I am working on an accordion menu with many div elements, each of which has its own unique id like:
<div id='sampe_1' class='sample'></div>
<div id='sampe_2' class='sample'></div>
<div id='sampe_3' class='sample'></div>
<div id='sampe_100' class='sample'></div>
For expanding and collapsing these divs, I have been using two different methods:
$("div[id^='sample_']");
This allows me to select all 100 divs at once. Then I loop through them and trigger the click event.
Alternatively,
I can directly apply a click event using the class name like so:
$('.sample').on('click');
Out of these two methods, I am wondering which one is better or if there is a more efficient approach?