Use jQuery to Replace a Word with a Link
by Bandicoot Marketing on | Posted in Tutorials | 7 comments
If you use a word multiple times on your site and you don’t feel like going through all your posts to replace every instance of it, you can use jQuery to search your page and do the replacing for you. I wanted to replace a word throughout an entire site with a link and all it took was a small piece of code.
If you don’t already have jQuery loaded into your page, include this before your closing
That will load up jQuery from Google.
Now you just need to include this in your site’s footer, before the closing
replace() function. The
i after the slash makes the search and replace case-insensitive, and the
g makes it global.
I have the script working on this page to replace every instance of the word jQuery with a link to the jQuery Web site.
7 comments for “Use jQuery to Replace a Word with a Link”