How to check a div/ element is hidden using jQuery?


I have a div where I show some information to user, and in my logic I hide/ unhide it multiple times (based on some conditions).
Somewhere else in my code to perform an action I need to check whether or not that particular div is hidden or not. How can I check this using jQuery?

1 Answer

5 years ago by

For example, if the following is your <div>

<div id="foo"> <p> some content </p> </div>

you can check whether or not the div is hidden by using the following code

if($("#foo").is(":hidden")){
 // its hidden
} else {
 // not hidden
}
5 years ago by Karthik Divi