jquery - How close other element when clicked using .slideToggle -
i'm trying make accordion menu, how ever, need menus open 1. how close other li when clicked?
below code use toggling menu. how target other li close when li clicked.
<li class="cat_parent"> <h2 class="head par_title">books</h2> <div class="content">01</div> <div class="content">02</div> </li> <li class="cat_parent"> <h2 class="head par_title">magazine</h2> <div class="content">01</div> <div class="content">02</div> <div class="content">03</div> <div class="content">04</div> </li> $(document).ready(function(){ ('.head').click(function(e){ e.preventdefault(); $(this).closest('li').find('.content').slidetoggle(); }); });
your appreciated!
try
$('.cat_parent').find('div').hide(); $('.head').click(function(e){ e.preventdefault(); $(this).siblings().slidedown('slow'); $(this).parents('.cat_parent').siblings().find('div').slideup('slow'); });
Comments
Post a Comment