Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use jQuery to check if all div's are hidden

How would I check if all the div's with class test are hidden. And if they are all hidden set wrap1 to hidden. Thanks.

<div id='wrap1'>
<div class="header">Header 1</div>
<div class='test'><a href="#">Test 1</a></div>
<div class='test'><a href="#">Test 2</a></div>
<div class='test'><a href="#">Test 3</a></div>
</div>

UPDATE: Thanks everyone for the really quick answers, I got it working. They were all very helpful.

like image 973
user149109 Avatar asked Aug 03 '09 15:08

user149109


People also ask

How do you check control is hide or not in jQuery?

To check if an element is hidden or not, jQuery :hidden selector can be used. .toggle() function is used to toggle the visibility of an element.

How do you check a DIV is hidden or not?

.is(":hidden") will return true if the selected element is hidden. If it's not hidden, then it will return false .

How do you know if an element is hidden?

Another way to check if an element is hidden is to use the window. getComputedStyle() method. It will return the display property value of the object. We can check if the string is equal to none meaning the element is hidden and do something.

Is visible in jQuery?

The :visible selector in jQuery is used to select every element which is currently visible. It works upon the visible elements. The elements that are consuming space in the document are considered visible elements. The height and width of visible elements are larger than 0.


1 Answers

You can do the check as by using selector as suggested above and to it like this:

 if ( $("div.test:visible").length === 0)
      $("#wrap1").hide( );
like image 185
Artem Barger Avatar answered Oct 01 '22 04:10

Artem Barger