Joonas
Joonas

Reputation: 7303

jQuery - Multiple links and multiple classes. Toggle on/off

I had this one problem yesterday and both solutions are here at the js section http://jsfiddle.net/6jm2s/22/

But now i have same problem ...except the classes that need to be removed are all different.

This should explain what i want... http://jsfiddle.net/YeWna/7/

Any thoughts?

Solution demo: http://jsfiddle.net/YeWna/16/

Upvotes: 0

Views: 495

Answers (1)

Robin
Robin

Reputation: 21894

var klasses = $.map($(".links a"), function(elt) {
    return $(elt).attr("class");
}).join(" ");
$(".links a").click(function(){
    var link = $(this),
        aBox = $(".aBox"),
        klass = link.attr("class");
    aBox.hasClass(klass) ? aBox.removeClass(klass) : aBox.removeClass(klasses).addClass(klass);

    return false;
})

Try that (updated)

Upvotes: 1

Related Questions