4
The Selector :visible
jQuery is used to search for an element when it is visible.
Example:
$(this).find('li:visible').addClass('color-red');
However, when trying to search for invisible elements, we do not have the selector :invisible
$(':invisible') // Error: Syntax error, unrecognized expression: unsupported pseudo: invisible
What is the reverse of
:visible
in jQuery?And how I could create the expression
:invisible
inside jQuery itself?
You can also use the
$('div:not(:visible)')
.– KaduAmaral
@Kaduamaral well seen! I joined this too.
– Sergio
Thanks for the correction!
– Wallace Maxters
Remembering that the . not(':Visible') and :Hidden are not exactly the same thing, see the jQuery documentation to see the difference
– Edson Horacio Junior
The best test to do is :
$('body').hide().is(':visible')
. For me, you’ve returnedtrue
. Then the:hidden
helped in my case :)– Wallace Maxters
Or we can still do:
$('div').filter(':not(:visible)')
. That’s how I was wearing it, but I asked if there was a simpler way– Wallace Maxters
@Wallacemaxters in this case then he’ll get all the
divs
existing and then filtering them to see which one is not visible, is a large execution of unnecessary codes. Of the listed forms I recommend is$('div:hidden')
, simple and direct. The example I gave also is an unnecessary writing would be doing($bool == TRUE && $bool != FALSE)
instead of just($bool)
.– KaduAmaral