E-Learning

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!

Avatar
About author

I, Dr. Michael J. Garbade is the co-founder of the Education Ecosystem (aka LiveEdu), ex-Amazon, GE, Rebate Networks, Y-combinator. Python, Django, and DevOps Engineer. Serial Entrepreneur. Experienced in raising venture funding. I speak English and German as mother tongues. I have a Masters in Business Administration and Physics, and a Ph.D. in Venture Capital Financing. Currently, I am the Project Lead on the community project -Nationalcoronalvirus Hotline I write subject matter expert technical and business articles in leading blogs like Opensource.com, Dzone.com, Cybrary, Businessinsider, Entrepreneur.com, TechinAsia, Coindesk, and Cointelegraph. I am a frequent speaker and panelist at tech and blockchain conferences around the globe. I serve as a start-up mentor at Axel Springer Accelerator, NY Edtech Accelerator, Seedstars, and Learnlaunch Accelerator. I love hackathons and often serve as a technical judge on hackathon panels.