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
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
Post a Comment