What is the inverse of :Visible in jQuery?

Asked

Viewed 189 times

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?

2 answers

9


  • 1

    You can also use the $('div:not(:visible)').

  • @Kaduamaral well seen! I joined this too.

  • Thanks for the correction!

  • Remembering that the . not(':Visible') and :Hidden are not exactly the same thing, see the jQuery documentation to see the difference

  • The best test to do is : $('body').hide().is(':visible'). For me, you’ve returned true. Then the :hidden helped in my case :)

  • 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

  • 1

    @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).

Show 2 more comments

3

Browser other questions tagged

You are not signed in. Login or sign up in order to post.