jquery - Selecting elements following a selected element -
i creating custom accordion menu using jquery.
what want accomplish this: if ul within ul (for example line 39 in image) set display... want change of ul tagged elements following, within specified div, no display
having no luck .next() or .nextall()
code example
<div id="wrapper"> <ul class="a-menu"> <li> main menu 1 <ul> <li>sub 1 menu 1</li> <li>sub 1 menu 2</li> </ul> </li> <li> main menu 2 <ul> <li> sub 2 menu 1 <ul> <li>sub 3 menu 1</li> <li>sub 3 menu 2</li> <li>sub 3 menu 3</li> </ul> </li> <li> sub 3 menu 2 <ul> <li> sub 3 menu 1</li> <li> sub 3 menu 2</li> </ul> </li> <li>sub 3 menu 3 </li> </ul> </li> <li> main menu 3 <ul> <li>sub 1 menu 1</li> <li>sub 1 menu 2</li> </ul> </li> </ul> </div>
figured out!
jquery
$("document").ready(function() { $('li').click(function(ev) { $(this).find('>ul').slidetoggle(); ev.stoppropagation(); $(this).nextall("li").toggleclass("hidden"); }); });
css
.hidden { display: none; }
Comments
Post a Comment