Reputation: 23613
With jQuery how can I run a function if no divs in a selection have a certain class?
There are multiple div.result. Initially they will all have a class of "hidden" but in time none of them will. Im running the following on different events:
if (!$(".result").hasClass("hidden")) {
$("body").addClass("all-shown");
}
Upvotes: 0
Views: 25
Reputation: 36702
Check the length of the returned set...
if (!$(".result.hidden").length) {
$("body").addClass("all-shown");
}
Example...
if (!$(".result.hidden").length) {
alert("no items");
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
Upvotes: 1