Setting the active class and removing it from all the rest

I have a couple of divs to scroll through. I need to set it in active mode (after the link has been clicked) to "active", and all other divs should remove this class.

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();
        }
    }); menuShow(),titleFadeOut();
});

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>
+3
source share
1 answer

why not just use addClass and removeClass:

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

to remove only selectedfrom divs, use this for the first line:

$("div.selected").removeClass("selected"); 
+6
source

All Articles