1
I have the following code. I tried to run inside the element with the ACTIVE class, a code that checked if it had the word VIOLET inside the element with the class TITLE. But instead of running only on the element with the ACTIVE class, it ran on everyone with the VIOLET word:
var Violet = /Violet/gi;
$('.title').append($('div').hasClass("active")).contents().each(function() {
if (this.nodeType === 3 && this.nodeValue.match(Violet)) {
alert('teste')
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul class="owl-1">
<div class="owl-item active">
<li>
<div class="title">Violet</div>
</li>
</div>
<div class="owl-item">
<li>
<div class="title">Violet</div>
</li>
</div>
<div class="owl-item">
<li>
<div class="title">Evergarden</div>
</li>
</div>
</ul>
Use two
find
is redundant:$('div.active').find('li').find('div.title').css('color','red');
... would suffice$('div.active div.title').css('color','red');
... see that you don’t even need.find()
– Sam