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