javascript - Jquery Slidetoggle, how to allow to show only one element? -


this html:

<ul>     <li>         list         <ul>             <li>item 1</li>             <li>item 2</li>             <li>item 3</li>             <li>item 4</li>             <li>item 5</li>         </ul>     </li>      <li>         list 2         <ul>             <li>item 1</li>             <li>item 2</li>             <li>item 3</li>             <li>item 4</li>         </ul>     </li> </ul> 

and js:

$('ul li ul').hide();  $('ul li').click(function() {     $(this).children().slidetoggle(); }); 

i want create slidetoggle, example: when user click "list" , after open user click list 2 list 1 hiding.

demo: http://jsfiddle.net/7dxab/ want 1 open when user click.

thanks!

try this:

$('ul li ul').hide();  $('ul li').click(function() {     var _this = $(this);     _this.children().slidetoggle();      $('ul > li').not(_this).children('ul').slideup(); }); 

you hide "ul"s in listn elements except 1 clicked.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -