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'); } }); 

online sample

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

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -