Here is my situation. I’m helping a client with their Woocommerce (WordPress) Site. I’ve been using jquery to hide the higher variation prices and only showing the lower price. There is the “-” that still shows and I want to remove that with jQuery. I’ve been trying for hours and not succeeded. Help would be appreciated.
Here is my HTML code:
<span class="price"><del><span class="amount">$13.29</span>â<span class="amount">$332.25</span>
</del> <ins><span class="amount">$10.63</span>â<span class="amount">$151.84</span></ins>
</span>
<div class="product-meta-wrapper">
<h3 class="heading-title product-title"><a href="http://sproutman.com/shop/product/beginners-dozen-seeds/">Beginnerâs Dozen Sprouting Seeds</a></h3>
<div class="second-rating"></div> <span class="price"><del><span class="amount">$99.92</span>
</del> <ins><span class="amount">$87.89</span></ins>
</span>
<div class="list_add_to_cart"><a href="/product-category/organic-sprouting-seeds/recommendations-for-beginners/?add-to-cart=650" rel="nofollow" data-product_id="650" data-product_sku="SPRTSAMP" class="button add_to_cart_button product_type_simple">Add to cart</a>
</div>
</div>
And my jquery code:
$(document).ready(function () {
var firstHighPrice = $('del span:nth-child(2)');
var secondHighPrice = $('ins span:nth-child(2)');
firstHighPrice.hide();
secondHighPrice.hide();
});
Link to JSFiddle: http://jsfiddle.net/a5Lyxsur/2/
If you know that the text before spans you are hinding is
-
that you also want to remove, then just usepreviousSibling
to get text node to remove:Demo: http://jsfiddle.net/a5Lyxsur/3/
If you put
<span></span>
tags around “-” like belowThen modify the selectors as shown below
Working sample is at http://jsfiddle.net/a5Lyxsur/4/
In this
each
function is applied to eachspan
withclass
price
and detach method to thedel
andins
elements and theirspan
elements within. Thenempty
method is used to remove the dash (-). Finally, the previously detached elements are appended back again. Fiddle