javascript - Jquery add and remove class to a div placed inside a li -
i wanna add , remove class div placed inside li, , when click li ineed remove rightshapeactive class activated div
<ul id="servicesleft"> <li class="left1"> <span>lorem ipsum</span> <div id="rightshape" class="t"></div> </li> <li class="left1"> <span>lorem ipsum</span> <div id="rightshape" class="t"></div> </li> <li class="left1"> <span>lorem ipsum</span> <div id="rightshape" class="t"></div> </li> </ul> jquery(document).ready(function() { $('#servicesleft').delegate('li', 'click', function() { $(this).find('#rightshape').addclass('rightshapeactive').siblings().removeclass('rightshapeactive'); }); });
this should work. after .find('#rightshape')
, selection referring div
, , not li
. .end
returns previous selection.
jquery(document).ready(function() { $('#servicesleft').delegate('li', 'click', function() { $(this).find('#rightshape') .addclass('rightshapeactive') .end() .siblings() .find('#rightshape') .removeclass('rightshapeactive'); }); });
this might better:
jquery(document).ready(function() { $('#servicesleft').delegate('li', 'click', function() { $('.rightshapeactive').removeclass('rightshapeactive'); $('#rightshape', this).addclass('rightshapeactive'); }); });
Comments
Post a Comment