开发者

jQuery if any of a certain class is hidden perform a task, else, perform another task

Is there a way to test if a certain element (.container) is hidden, in a whole document? Such as (which doesn't work properly):

$(".showall").click(
    function () {
        if ($(".container").is("hidden"))
                {perform a task}
            else
                {retur开发者_如何转开发n false;}
    });


It sounds like you want to test if at least one of the .container elements is hidden.

If so, you can use the :hidden selector, and check the length property to see how many were returned.

$(".showall").click(
    function () {
        if ($(".container:hidden").length)
             // found at least one hidden
        else
             // didn't find any hidden
    });

If you wanted to test to see if all were hidden, use the :visible selector like this:

$(".showall").click(
    function () {
        if ($(".container:visible").length)
             // found at least one visible
        else
             // didn't find any visible
    });


You mean to use is visible:

$(".showall").click(
    function () {
        if ($('.container').is(":visible") == false)
                {perform a task}
            else
                {return false;}
    });
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜