Reputation: 47
Is it possible to replace exact text with other text after the page has loaded with jquery?
For example, my data is being generated dynamically within a php loop. Once it finishes outputting the information, I'd like to do a find and replace, replacing the phrase "test phrase 1" with "test phrase 2" throughout the page. Is this possible?
Upvotes: 1
Views: 2605
Reputation: 40695
You don't need yet another plugin for this task.
The jQuery function .replace() is just fine for that. You can use it on any attribut or text. Example:
var href = $this.attr("href").replace(/param\/.*\//, "param/newparam/");
This - using regex - takes an url and replaces the first occurance of param/anything/
with param/newparam
.
Upvotes: 1
Reputation: 9888
I think you will find jquery-translate useful. It even has method that you need, namely: $().nodesContainingText(...)
Upvotes: 0