I'm trying to add a class to a single div (or multiple, depending on what the search results return) however the code I have below is adding the class to all of the .price.full
divs on the page, rather than just applying to the one(s) that matches the :has
.
jQuery(document).ready(function() {
jQuery('.price.full p.price:has(small)').closest('.price.full').addClass('price-enquiry');
});
The HTML
<div class="price-rating">
<span class="price full price-enquiry">
<div itemprop="offers" itemscope="" itemtype="http://schema.org/Offer">
<p class="price"><small>+44 (0) 1395<br> 444099</small></p>
<meta itemprop="price" content="0">
<meta itemprop="priceCurrency" content="GBP">
<link itemprop="availability" href="http://schema.org/InStock">
</div>
</span>
<div class="product-codes">
<span class="oe-code">
OE Code: 82-5323/4
</span><!-- .oe-code -->
<span class="sku">
SKU: MG41
</span>
</div><!-- .product-codes -->
</div>
`.
– Fabian Klötzl Mar 17 '17 at 13:13