How to tell if a div is visible / hidden using JQuery

Category : JQuery/JScript

You have a DIV and want to check if it is visible

Use the is() function passing “:visible” :

if( $('#myDiv').is(':visible') ) {}

Hidden

This is the same as checking if an element is visible but uses :hidden instead and the logic is the reverse:

if( $('#myDiv').is(':hidden') ) {}


Elements will return TRUE to the Hidden check even if they are not but take up no space!

Make the IS NOT check to combat this.

if( !$('#myDiv').is(':visible') {}
}

You can use the visible parameter to loop through all visible divs

$("#mydiv div:visible").each( function() {}

Post a comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word