I want to addClass()
strike
to class priceis
if the class specialprice
exists. Currently, it is only putting it on the first element, not on every element that appears on the page. I need it to check for all elements with the class specialprice
.
<font class="pricecolor colors_productprice specialprice">
<span class="PageText_L483n">
<font class="text colors_text"><b>Regular Price:<br> </b></font>
<span id="priceis">$2,492<sup>.38</sup></span>
</span>
</font>
<script>
$('.specialprice').find('.priceis').addClass('strike');
</script>
maybe something like this? still not sure about the explanation of your question, not clear..
$(function() {
$('.specialprice').each(function() {
$(this).find('.priceis').addClass('strike');
});
}
EDIT: just realized maybe you wanted it like this?
$('.specialprice').each(function() {
$(this).find('*').addClass('strike');
});
$('.specialprice.priceis').addClass('strike');
?
Your HTML is wrong
<span id="priceis">
You probably meant to set class
instead of id
.
<span class="priceis">
Your current code will work if you fix your HTML.
You might want to see this answer, it explains why a script doesn't work when included before the DOM elements.
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