Reputation: 697
There is some number of div's which will be in one wrapper, like this:
<div class="wrapper">
<div class="container"></div>
<div class="container"></div>
<div class="container"></div>
<div class="container"></div>
</div>
There can be any amount of divs container
. How could I trigger event only if all of this divs aren't visible?
I was thinking about something like that, but code seems not to be working:
if (!$('.container:visible')) {alert("no container found")}
or
if ($('.container:visible') == 0) {alert("no container found")}
JSFiddle http://jsfiddle.net/k4eKf/
What's the possible ways to achieve that?
Upvotes: 0
Views: 45
Reputation: 2137
You have to use is()
function to check the existence of property.
Use:
var visible=$('.container').is(":visible");
if(visible==true)
{
//Do something here
}
Read the docs about is()
function here
Upvotes: 0
Reputation: 82251
It should be:
$('.container').is(":visible");
If this returns true, then it means that some div with class .container
is visible. You will need the condition:
if(!$('.container').is(":visible")){
//all container are hidden
}
Upvotes: 3