Learn JavaScript – How To Check if An Element is Hidden Using jQuery

 
When we are using jQuery in JavaScript, often we want to take an action based on the state of an element. One that is widely used is if the state of the element is visible or not. An element is visible when if it consumes space in the document. Visible elements have a height or width larger than zero.

To find out if an element is hidden, we basically have two tools to use. The first that we’ll see use is: visible.
 

JavaScript – using: visible with jQuery

The :visible selector checks whether the element is visible within the DOM.


Below we have an example using this selector to determine an action within the program:


To check if the div #countires is visible, use the is () function with the selector “: visible”:


Loop the visible divs inside the div #countries:


The result will be:


 

JavaScript – using: hidden in jQuery

The :hidden selector perform the opposite check of the previous one. It checks if the element is hidden inside the DOM


With these two selectors, you can verify the state of the element and perform something within the code based on the response. Do you know other ways to do this operation in JavaScript?  Share your comments in the section below!

If you want to explore other questions, you can check our videos on JavaScript. Below are some examples:

You can also subscribe to some channels that broadcast in JavaScript, such as the following:

JavaScript how to check if an element is hidden using jQuery programmingObsidianBlk

JavaScript how to check if an element is hidden using jQuery programming TimMikeladze

Another cool way to find out interesting things about JavaScript is to access our project page!

(Visited 760 times, 5 visits today)
  • Edgar Burkhart

    This was brilliantly done thanks. (Y)

Read previous post:
javascript-how-to-get-a-value-in-dropdown-list-1
Learn JavaScript – How to Get a Select Value in a Dropdown List?

  How to recover in JavaScript, the value of an option in a dropdown list? Before anything else, we must...

Close