jquery - Hiding and showing list under ul tags -


how use jquery hide/show (toggle) elements class secondlevel upon clicking on toplevel link?

<ul> <li><a class="toplevel" href="#">hardware</a> <ul>     <li><a class="secondlevel" href="#">bottling</a></li>     <li><a class="secondlevel" href="#">brewing</a></li>     <li><a class="secondlevel" href="#">cleaning</a></li>     <li><a class="secondlevel" href="#">fermenting</a></li>     <li><a class="secondlevel" href="#">kegging</a></li>     <li><a class="secondlevel" href="#">measuring</a></li>     <li><a class="secondlevel" href="#">testing</a></li> </ul> </li> 

like this? jsfiddle

$('li ul').hide();  $('.toplevel').on('click', function() {     $(this).siblings('ul').slidetoggle();     return false; }); 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -