GEM-I'm a dedicated Wordpress & Squarespace developer

How do I check if an element is hidden in jQuery?

How do I toggle the visibility of an element using .hide().show(), or .toggle()?

How do I test if an element is visible or hidden?

Solution No 1

We use jQuery’s is() to check the selected element with another element, selector or any jQuery object. This method traverses along the DOM elements to find a match, which satisfies the passed parameter. It will return true if there is a match, otherwise return false.

// Checks CSS content for display:[none|block], ignores visibility:[true|false]

// The same works with hidden

Solution No 2

You can use the hidden selector:

// Matches all elements that are hidden

And the visible selector:

// Matches all elements that are visible
Spread the Code



You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *