user55655
user55655

Reputation: 47

Replace particular text after the page is loaded with jquery

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

Answers (2)

markus
markus

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

Marko Dumic
Marko Dumic

Reputation: 9888

I think you will find jquery-translate useful. It even has method that you need, namely: $().nodesContainingText(...)

Upvotes: 0

Related Questions