tags:

views:

1570

answers:

2

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?

A: 

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

Marko Dumic
+1  A: 

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.

tharkun