Reputation: 426
I want to catch if children of element have two classes, so for example if we have something like this:
HTML
<div class="mainElement">
<div>
<p class="thisClass">
</p>
</div>
<div>
<div>
<div class="andThisClass">
</div>
</div>
</div>
I would like to catch it and remove it, for example like this:
jQuery
if($('.mainElement').hasClasses('thisClass, andThisClass') ){
$('.mainElement').css('display', 'none');
}
Though this obviously wouldn't work, I've also tried with .find().
Upvotes: 1
Views: 49
Reputation: 67217
You could do it with has
filter,
var cache = $('.mainElement');
cache.toggle(!(cache.has('.thisClass').length && cache.has('.andThisClass').length));
Upvotes: 2
Reputation: 25352
You can do it using .find
Try like this
if ($('.mainElement').find('.thisClass').length>0 && $('.mainElement').find('.andThisClass').length>0) {
console.log("contain");
}
you didn't close your tag properly
here
</p>
</div <- here
<div>
<div>
Upvotes: 1