javascript - jQuery slideToggle callback function and toggleclass -
html
<div class="a"> <div class="b">click</div> <div class="c"></div> </div> <div class="a"> <div class="b">click</div> <div class="c"></div> </div> <div class="a"> <div class="b">click</div> <div class="c"></div> </div>
jquery
$('.c').hide(); $('.b').click(function(){ $(this).next('.c').fadetoggle(); if($('.b').eq(0).is(this)){ $(this).toggleclass('yellow'); } });
how make once slidetoggle
finishes start toggleclass
, 1st box, i'd change yellow color once fadetoggle finishes
you can use fadetoggle
's callback function:
working demo: http://jsfiddle.net/kqc2b/
$('.b').click(function () { var = this; $(this).next('.c').fadetoggle(function() { if ( $('.b').eq(0).is(that) ) { $(that).toggleclass('yellow'); } }); });
Comments
Post a Comment