I need to select the second image inside of a div (.entry-content) unless the image has a specific parent class. Here is an example of my attempts
In the example below, I would need to select the third image since the second image has the parent class of parent-div.
jQuery(".entry-content").each(function() {
jQuery(this).find("img:eq(1):not(:parent.parent-div)").addClass("second-img");
});
// or
jQuery(".entry-content").each(function() {
jQuery(this).find("img:eq(1)").not().parent(".parent-div").addClass("second-img");
});
.second-img { border: 1px solid black; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="entry-content">
<p></p>
<p></p>
<p><img /></p>
<div class="parent-div"><img /></div>
<div><img /></div>
<div></div>
<div class="parent-div"><img /></div>
<p></p>
<img />
<img />
<p></p>
<p><img /></p>
</div>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…