I'm playing around with finding and replacing text.
The only problem I'm having is finding a text string, that is not attached to an element with an ID. Otherwise, it would be easy.
I'm trying something like this:
$("*").each(function () {
$(this).html(this.html().replace('Original Text','New Text'));
});
Not working too well.
Anyone run into this before?
Also, if I have several words or phrases to find and replace, how does that affect the speed/processing power of the user's browser? Is it a memory hog?
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.
$("*").contents().each(function() {
if(this.nodeType == 3)
this.nodeValue = this.nodeValue.replace("old", "new");
});
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