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

»

Docker: How To Build Better Development Security With It

The top concern among developers and DevOps teams is security within ...

»

Mobile Development: How to Reduce Costs

Modern markets have become so competitive that it has become vital ...

»

Know-How DevOps Benefits Your Business

The organizations in this current fast-paced environment need to ...

»

10 Best Prototyping Tools for UI/UX Designers

Website design for a client gets only successful if you follow their ...

»

Social Media Marketing: Strategy To Boost Ecommerce-Traffic

According to a recent study, the experts revealed that people aged ...

»

How Flutter Can Help Reduce Overall Mobile App Development Cost?

Before jumping on answering the question, let me first walk you ...

»

Which One is Better? DigitalOcean Or AWS?

Digitalocean or AWS: Picking a cloud service for your application or ...

»

Killing way to select Domain Name and Hosting

Planning to launch your online presence? We know it’s all very ...

»

7+ blogs to inspire how they made more than $200 in a day

On this page I want to go through the blogs on how they earn money ...