jQuery detect visible but hidden elements

后端 未结 3 1760
情深已故
情深已故 2020-12-29 10:17

This seems like it should be fairly easy - but I can\'t find the right selector for it

According to the docs (http://api.jquery.com/hidden-selector/ and http://api.j

3条回答
  •  孤城傲影
    2020-12-29 10:47

    If this is something you'll commonly use, make your own selector :) Here's an example:

    jQuery.expr[':'].hiddenByParent = function(a) { 
       return jQuery(a).is(':hidden') && jQuery(a).css('display') != 'none'; 
    };
    

    You can use it like this, test markup:

    Examples of use:

    $("div:hiddenByParent").length;​​​​​​​​​​​​​​​​​​ // "2" (plain div + child match)
    $("#child").is(":hiddenByParent"); // true
    

    Alternatively, you can use the .filter() function like this:

    $('selector').filter(function() {
      return $(this).is(':hidden') && $(this).css('display') != 'none';
    }
    

提交回复
热议问题