如何在javascript函数中包含多个类/子类

时间:2015-04-28 10:42:34

标签: javascript jquery class syntax subclass

我有这个javascript:

$(document).ready(function() {
    $('#holder').toggleClass("visible");

    $('a.link').click(function(event) {
        // Over-rides the link
        event.preventDefault();
        // Sets the new destination to the href of the link
        newLocation = this.href;
        color = $(this).data("color");
        $('body').css('background-color', color );
        $('#holder').css('opacity','0' );
        // Delays action
        window.setTimeout(function() {
            // Redirects to new destination
                window.location = newLocation;
        }, 250);
    });

    $('h1').click(function(event) {
        $('#holder').toggleClass("visible");
    });

});

我想将类body的使用更改为body.subsection.container之类的内容。我该怎么做呢 ?

此外,我想要包含多个类,例如body.subsection.container1body.subsection.container2

对此的任何帮助都非常感谢。

干杯,

格雷格。

1 个答案:

答案 0 :(得分:0)

假设你的意思是在body元素的某个地方的某个元素中找到一个带有类container1或container2的元素,你可以这样做:

$('body .subsection .container1,body .subsection .container2')

body.subsection.container会找到本身具有类子部分和类容器的正文标记。

相关问题