开发者

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

开发者 https://www.devze.com 2023-02-08 16:46 出处:网络
I had this one problem yesterday and both solutions are here at the js section http://jsfiddle.net/6jm2s/22/

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 wha开发者_JS百科t i want... http://jsfiddle.net/YeWna/7/

Any thoughts?

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


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)

0

精彩评论

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