jQuery - 突出显示具有相同类的Div

时间:2014-09-29 16:49:36

标签: jquery

我有一个使用jQuery编写的例程,如果他们的属性与按钮的属性匹配,我想突出显示div ...

$links = $('.property');
$links.click(function(e) {
    //Get our variables, simply $(this) and the colour
    var $this = $(this),
        color = $this.data('col');

    //Toggle the active class on this link
    $this.toggleClass('active');

    //Remove .main on all .test's
    $(".slayout").removeClass("main");
    $(".product").addClass("trans");
    $(".product").removeClass("main");

    //Map the active link's data-col with a dot attributes to an array
    //Join it up to make a selector
    var selector = $links.filter('.active').map(function(){
        return "."+$(this).data('col');
    }).get().join('');

    //Add the class back on to matches
    $(selector).addClass('main');

    //Finally, prevent the default action
    e.preventDefault();
});

http://jsfiddle.net/os40xLof/

出于某种原因,它不按我想要的方式工作。如果我点击“热”'然后我希望这两个项目有“热”和“热”。在其中突出显示,其余部分将变暗。

但出于某种原因,一切都开始变暗,我哪里出错!

1 个答案:

答案 0 :(得分:1)

您的CSS错误,为.slayout规则增加了更多特异性:

.main { opacity:1; }
.main.slayout { opacity:0.3; }