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