Tuesday, 15 June 2010

jquery - Why is removeClass is not working in this case? -



jquery - Why is removeClass is not working in this case? -

i have following:

js:

$('.home-toggle').click(function() { scroll(); $('#content twelvecol > a').removeclass('selected-tile'); $(this).addclass('selected-tile'); $('.hidden').hide(); $('.home-container').slidedown(); }); $('.why-toggle').click(function() { scroll(); $('#content twelvecol > a').removeclass('selected-tile'); $(this).addclass('selected-tile'); $('.hidden').hide(); $('.why-container').slidedown(); });

html:

<div id="content" class="container" style="display:none;"> <div class="row"> <div class="twelvecol"> <a href="#" class="home-toggle tile first"> <img class="tile-top" src="images/tile1.png" alt="" /> <img class="tile-bottom" src="images/tile1h.png" alt="" /> </a> <a href="#" class="why-toggle tile"> <img class="tile-top" src="images/tile2.png" alt="" /> <img class="tile-bottom" src="images/tile2h.png" alt="" /> </a> <a href="#" class="solutions-toggle tile last"> <img class="tile-top" src="images/tile3.png" alt="" /> <img class="tile-bottom" src="images/tile3h.png" alt="" /> </a>

so .selected-tile should removed other .tile 1 time click on one.

but reason, class still remains in other tiles.

what problem?

you have bug in selector

$('#content twelvecol > a')

should

$('#content .twelvecol > a') // ^ dot

since latter selects anchors top children within of container with class of twelvecol, within of element id of content.

jquery

No comments:

Post a Comment