0

I am trying to remove text from the label, but I want to keep the span text within it. Here is the part I want to remove: http://prntscr.com/kwblwc

<label for="wc_checkout_add_ons_2_yes" class="checkbox ">Yes (
  <span class="woocommerce-Price-amount amount">
  <span class="woocommerce-Price-currencySymbol">€</span>
  4.95</span>)
</label>

So basically I want it just to stay €4.95

Omid Nikrah
  • 2,444
  • 3
  • 15
  • 30

1 Answers1

0

You can filter your div by nodeType. This code should work.

$(function() {
  $('.checkbox').contents().filter(function() {
    return this.nodeType === 3;
  }).remove();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<label for="wc_checkout_add_ons_2_yes" class="checkbox ">Yes (
  <span class="woocommerce-Price-amount amount">
  <span class="woocommerce-Price-currencySymbol">€</span>
  4.95</span>)
</label>

https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType

Juan
  • 4,910
  • 3
  • 37
  • 46
akcoban
  • 953
  • 7
  • 14