william william - 6 months ago 19
jQuery Question

Jquery: Find Text and replace

<div id="id1">
<p>
apple
</p>
<p>
ball
</p>
<p>
cat
</p>
<p>
dogsss
</p>
</div>


How Do I change
dogsss
to
dollsss
using
jquery
?

Answer

You can try

$('#id1 p').each(function() {
    var text = $(this).text();
    $(this).text(text.replace('dog', 'doll')); 
});

http://jsfiddle.net/2EvGF/

You could use instead .html() and/or further sophisticate the .replace() call according to your needs