开发者

setting active class and removing it from all others

I've got a couple of divs to scroll between. I need to set the one in active view (after a link was clicked) to 'active' and all the other div's should have that class removed.

Using toggle I can't get it to work.

$('.projecten').click(function () {
$('#due').toggleClass('selected'),
    $paneTarget.stop().scrollTo('#due', 800, {
        margin: true,
        onAfter: function () {
            $("body").animate({
                backgroundColor: "#1f8311"
            }, 800),projectenfade();
        }
    }开发者_JS百科); menuShow(),titleFadeOut();
});

the html

<div id="due" class="elements">
                    <h3 class="resizeme">...</h3>
                </div>
<div id="otto" class="elements">
                    <h3 class="resizeme">...</h3>
                </div>
<div id="etc" class="elements">
                    <h3 class="resizeme">...</h3>
                </div>

...

<div id="menu">

<p>
        <a class="welkom pointme">Welkom</a> <a class="blog pointme">Blog</a> <a class="media pointme">Media</a> <a class="projecten pointme">Projecten</a> <a class="contact pointme">Contact</a> 
        </p>
    </div>


why not just use addClass and removeClass:

$(".selected").removeClass("selected"); 
$(this).addClass("selected");

to only remove selected from divs use this for the first line:

$("div.selected").removeClass("selected"); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜