4

I want to find and replace text with jquery. I want to change "SKU:" to "art nu."

<span itemprop="productID" class="sku_wrapper">
   SKU: 
   <span class="sku">
      5-144
   </span>.
</span>

I tried:

$(".product_meta>.sku_wrapper:contains('SKU:')" ).text('art nu.');

but this delete the child span sku.

Hope someone has a solution...

Maarten Heideman
  • 545
  • 1
  • 9
  • 18

2 Answers2

12

since jquery 1.8 you can do it also like this:

$(".sku_wrapper").html(function(i,t){
    return t.replace('SKU:','art nu.')
});
reyaner
  • 2,799
  • 1
  • 12
  • 17
1

Did you simply try

$(".sku_wrapper" ).each(function(){
    $this = $(this);
    $this.html($this.html().replace('SKU:','art nu.'));
});
Robin Leboeuf
  • 2,096
  • 1
  • 13
  • 14