Check if element is visible or hidden in jQuery?

  • The below code will help to identify if the element is visible or not:

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

However, :visible will also check if the parent elements are visible.

  • The other alternative is by using the hidden and visible selector as shown below:

// Matches all element that are hidden

$('element:hidden')

// Matches all element that are visible

$('element:visible')

  • To check the display property of single element and not the parent element we have third alternative

if($(element).css('display')=='none'){

// element is hidden

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s