Reputation: 2814
At the moment I am doing this:
bl = !$("#divModal1").is(":visible") &&
!$("#divModal2").is(":visible") &&
!$("#divModal3").is(":visible") &&
!$("#divModal4").is(":visible") &&
!$("#divModal5").is(":visible");
where divModal# are all divs who share the same class class="divModalDialog".
Is there a better way of doing this by checking the class rather than each individual one?
Basically bl must be false if one or more of these divModal# is showing.
Upvotes: 3
Views: 13353
Reputation: 15846
:visible
pseudo class can be used for getting visible elements.
bl = ! $(".divModalDialog:visible").length > 0
Upvotes: 1
Reputation: 11
If you want to check if all divs
are not visible
you can do this:
var modalDialogsCount = $(".divModalDialog").length;
var returnValue = modalDialogsCount == !$(".divModalDialog:visible").length ? true : false;
This code checks if all divModalDialog
are not visible
and returns true
if it's true.
Upvotes: 0
Reputation: 7318
From the .is
documentation:
Check the current matched set of elements against a selector, element, or jQuery object and return
true
if at least one of these elements matches the given arguments.
Therefore, simply using the class name suffices, since .is(":visible")
will return true if any of them are visible.
bl = !$(".divModalDialog").is(":visible");
Upvotes: 12