Skip to content

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

Find out how to find if an element is visible or hiddenin jQuery. Learn how to get the state of a toggled element in jQuery.

If you want to check if the element’s display property is none or block. Please note that this solution ignores visibility (true / false).

$(element).is(":visible"); 

You can also check for ‘hidden’. It works the same way as the above.

$(element).is(":hidden");

The is() 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 returns false.

The above two solutions can be combined to a single statement with css like..

if ( $(element).css('display') == 'none' || $(element).css("visibility") == "hidden"){
    // your code
}
$(element).is(":visible"); 
See also  How to handle paste event in textarea HTML element?

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.