0

I would like to remove only text part but not variable.
In following image I am trying to translate this line via JQuery. following is the code I am using:

Want to change only text not the part which is enclosed in strong tag.

$('.content-box__row div:nth-child(3)').text('');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div role="cell" class="review-block__content" data-review-section="shipping-cost">
        Passport Priority Duties and Taxes Paid
        ·
        <strong class="emphasis">
          <span class="skeleton-while-loading--inline">14,96&nbsp;€</span>
        </strong>

    </div>

enter image description here

Roko C. Buljan
  • 196,159
  • 39
  • 305
  • 313
  • 2
    Try look at https://stackoverflow.com/a/17852238/2943218 – Carsten Løvbo Andersen Oct 10 '22 at 06:08
  • You can wrap what you need deleted in a separate `span` and target the new `span` instead – otejiri Oct 10 '22 at 06:10
  • @otejiri I can't edit this page. Shopify doesn't let us. – Apoorva Singh Oct 10 '22 at 06:12
  • you can edit the span: `$('.skeleton-while-loading--inline').text('some text');` – zb22 Oct 10 '22 at 06:12
  • @zb22, want to replace "Passport Priority Duties and Taxes Paid" this part of the code – Apoorva Singh Oct 10 '22 at 06:13
  • @CarstenLøvboAndersen I think following code will work , will you please help me to apply this in my current code. function removeText(element){ var newElement = $('<' + element[0].nodeName + '/>'); for(i=0; i < item.attributes.length; i++) { newElement.attr(item.attributes[i].name, item.attributes[i].value); } element.children().each(function(){ newElement.append(this); }); element.replaceWith(newElement); } – Apoorva Singh Oct 10 '22 at 06:20
  • @CarstenLøvboAndersen I want to replace it with "Droits et taxes de passeport prioritaires payés" – Apoorva Singh Oct 10 '22 at 06:21

1 Answers1

0

You can do it like this:

$('.content-box__row div:nth-child(3)').contents().filter(function() {
  return (this.nodeType == 3);
}).first().replaceWith("Droits et taxes de passeport prioritaires payés");

This will only replace the first part, aka what you want..

$('.content-box__row div:nth-child(3)').contents().filter(function() {
  return (this.nodeType == 3);
}).first().replaceWith("Droits et taxes de passeport prioritaires payés");
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="content-box__row">
  <div></div>
  <div></div>
  <div role="cell" class="review-block__content" data-review-section="shipping-cost">
    Passport Priority Duties and Taxes Paid ·
    <strong class="emphasis">
          <span class="skeleton-while-loading--inline">14,96&nbsp;€</span>
        </strong>

  </div>
</div>
Carsten Løvbo Andersen
  • 26,637
  • 10
  • 47
  • 77