javascript - jquery last child border if..else -


html

<div class="aa">     <div class="bb">1     </div>      <div class="cc">a     </div> </div> <div class="aa">     <div class="bb">2     </div>      <div class="cc">b     </div> </div> 

jquery

$('.bb:last').addclass('red'); $('.bb').click(function(){     $(this).next('.cc').fadetoggle();     if(!$('.cc:last').is(':hidden')){         if($('.bb:last').hasclass('red')){             $('.cc:last').addclass('red');             $('.bb:last').removeclass('red');         }     }else{     $('.bb:last').addclass('red');   } }); 

online sample -fiddle

when click box 2 border should removed bb assigned 'cc', second click border should go bb whenever cannot right. else{$('.bb:last').addclass('red');} not working.

could please me out? thanks

i think should solve problem having.

$('.bb:last').addclass('red'); $('.bb').click(function(){     $(this).next('.cc').fadetoggle();     if($('.bb:last').is(this)){         $(this).toggleclass('red');     } }); 

here link fiddle.


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 -