I'm trying to detect if any of the sub-divs within the parent "gallery" div have a class of "show".
<div id="gallery">
<div class="show"></div>
<div></div>
<div></div>
</div>
if (TEST CONDITION) {
alert('sub element with the class show found');
} else {
alert('not found');
}
It doesn't have to be in a if/else format. To be able to do this in a jQuery chainning sort of way would be better.
This should do:
if ($("#gallery > div.show").length > 0)
if you wish to keep jQuery chaining capability, use:
$("#gallery").has(".show").css("background","red"); //For example..
How about:
$("#gallery div").each(function (index, element) {
if($(element).hasClass("show")) {
//do your stuff
}
});
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