javascript - jQuery .prev() not working well -
i coding front-end of shopping website , scenario is: if have sale offer first previous price must line-through , beside price € inserted.
so jquery :
$(document).ready(function () { if ($('.price span.price-new').text().length != '') { this.prev('.price span.price-new').before("€").text(); this.prev("span").css({"text-decoration": "line-through"}); } });
and html:
<?php foreach( $this->products() $products) { echo '<div class="price"><span class="price-old">€ '.$products['price'].'</span>'. '<span class="price-new">'.$products['special_price'].'</span></div>'.'</div>';}?>
both of them didn't work. tried $(this) didn't work , because of have many price-new class can't mentioned specific class edit, use prevuntil still nothing.
shouldn't more this?
$(document).ready(function () { $('.price-old').css({"text-decoration": "line-through"}); $('.price-new').text(function(index, old_text) { return "€" + old_text; }) });
(what code for?)
Comments
Post a Comment