开发者

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 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜