简体   繁体   中英

jquery expand firlst ul>li>ul of parent

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!

http://jsfiddle.net/trrJp/1/

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.

First Child Selector

Working Fiddle

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM