Find and replace multiple text

by TwistedFirestarter

HTML

<div id="id1">
  <p>
    apple
  </p>
  <p>
    ball
  </p>
  <p>
    cat
  </p>
  <p>
    1 dogsss 2 dogsss 3 dogsss 4 dogsss
  </p>
</div>

JavaScript

$('#id1 p').each(function() {
  var text = $(this).text();
  // Use global flag i.e. g in the regex to replace all occurrences
  $(this).text(text.replace(/dog/g, 'doll'));
});