i have some jquery thats expanding/collapsing on click. i would like the first item to be expanded by default but im having trouble with the jquery. i've tried a few different angles to no avail. any help would be much appreciated!
If your issue is only you want the first item to open, after you setup all the menu jquery you can do something like this:
$('#menu li:first').slideToggle();
Or you could simulate a click:
$('#menu li:first').click();
The actual code is dependent on your actual implementation and how you'd open it but the general idea is to trigger the first element to open.
You can keep the first item expanded by default with the following line
$('#collapser li:first-child > ul').show();
What it does is selects the first li
and then select the ul
within that li
and show
that.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.