I need to run a function inside a conditional statement based on whether or not 3 elements have a class.
In short, if (elm1, elm2, elm3) have the class "include" then ring true. But all 3 elements must have the class, it can not ring true if only 2 or 1 has the class.
<div class="elm1" class="include"></div>
<div class="elm2" class="include"></div>
<div class="elm3" class="include"></div>
jQuery('#search-submit').click(function() {
if (#elm1, #elm2, #elm3).hasClass('include'){
/* return true */
} else {
/* return false */
}
}
Needless to say this doesn't work.
You can do something like
<div class="elm1 include"></div>
<div class="elm2 include"></div>
<div class="elm3 include"></div>
var classNotFound = false;
$('.elm1, .elm2, .elm3').each(function() {
if (!$(this).hasClass('include')){
classNotFound = true;
}
});
return classNotFound;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With