javascript - last child click doesnt change -
when select box 2
, i'd border become black.
click should go yellow.
the first click goes right second click stays black. can fix adding class, don't want to.
how else can this?
this code:
<div class="aa"> <div class="bb">1</div> <div class="cc"></div> </div> <div class="aa"> <div class="bb">2</div> <div class="cc"></div> </div>
$('.bb:last').addclass('yellow'); $('.bb').click(function () { $(this).next('.cc').fadetoggle(); if (!$('.cc:last').is(':hidden')) { $('.bb:last').addclass('black'); } else { $('.bb:last').removeclass('black'); $('.bb:last').addclass('yellow'); } });
.bb { background:red; width:90px; height:30px } .cc { background:blue; width:90px; height:30px; display:none; } .yellow { border:3px solid yellow; } .black { border:3px solid black; }
sample fiddle
check fiddle
you need remove class if has it.
$('.bb:last').addclass('yellow'); $('.bb').click(function () { $(this).next('.cc').fadetoggle(); if (!$('.cc:last').is(':hidden')) { if ($('.bb:last').hasclass('black')) { $('.bb:last').removeclass('black'); } else { $('.bb:last').addclass('black'); } } else { $('.bb:last').addclass('yellow'); } });
Comments
Post a Comment