How to Check the Visibility of an Element Using jQuery?


In the  jQuery versions before 1.3.2  an element was regarded as Visible if the CSS Visibility Property of that element was not defined as “Hidden” or if the CSS Display Property of that was defined as  “Visible “ or  it was an element with an input type not equal to “Hidden”. There are several options available to test whether an element is hidden or visible with jQuery. Nowadays with the later versions of jQuery the visibility of an element is determined by taking into consideration the height and width of the element. The element is considered to be visible if the height or width of the element is greater than zero otherwise the element is considered as Hidden.

a) We can make use of a Pure Selector to find out the visibility of an element and this method is considered to render the best performance than other methods. Below is the sample code listed for the same:

if ($('element_name:visible').length > 0){

alert(‘Element is Visible (Verified Using a Pure Selector)!’);

}

b) Using the is() Method of jQuery

if ($('element_name').is(':visible')) {

alert(‘Element is Visible (Verified Using is() Method)!’);

}

c) Using the filter() Method of jQuery

if ($('element_name').filter(':visible'). length >0) {

alert(‘Element is Visible (Verified Using filter() Method)!’);

}

 

Recently Published

»

Combine HTML5 & Bootstrap As Key Ingredients For Rebooting Your Business

HTML5 has achieved the tremendous heights in the recent years owing ...

»

10 Tips On Social Media That Will Land Your Dream Job

A job search trends survey conducted by Jobvite showed that 48% of ...

»

10 Best Node.js Frameworks For Web And Apps Development

Node.js is counted among one of the most renowned JavaScript runtime ...

»

Fetch Your Customers : Retail Commerce

As listening the word commerce it comes in our mind that it is ...

»

Best App Design Practices for 2016

The year 2015 witnessed some groundbreaking revolution regarding app ...

»

9 Websites To Visit For Exemplary Footer Design Inspiration

When we set out to design a website, our primary focus is on the ...

»

What are the Cloud Computing trends to dominate in 2016

With Cloud computing, it has developed cell phones into a remote ...

»

How to Show Related Posts in WordPress Without a Plugin?

Making your visitors go through each post increases the browsing time ...

»

Noteworthy Facts About Android App Piracy and How It Can Be Dealt With

Are you a gaming aficionado, and obsessed with gaming apps? Do you ...