<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
?
split("By:"). join("")); }); This removes any occurrence of "By:" in any element. If you want to target specfic type of elements, simply change $(':contains("By:")') to include whatever selector suits you.
To change text inside an element using jQuery, use the text() method.
We can replace HTML elements using the jQuery . replaceWith() method. With the jQuery replaceWith() method, we can replace each element in the set of matched elements with the provided new content and return the set of elements that were removed.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With