javascript - jquery class toggle not closing previous -


html

<div class="wrap"> <div class="t1">    head 1 </div> <div class="t2">     hi </div> </div> <div class="wrap"> <div class="t1"> head 2 </div> <div class="t2">     hi2 </div> </div> 

jquery

$(".t2").hide(); $(".t1").click(function(){ $(this).next(".t2").toggle(); }); 

i pressed first t1 t2 opening , when press second t1,first t2 should close still open

http://jsfiddle.net/q539mqon/3/

you need hide in click handler

var $t2s = $(".t2").hide(); $(".t1").click(function () {     var $t2 = $(this).next(".t2").toggle();     $t2s.not($t2).hide(); }); 

demo: fiddle


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -