[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 290
  • Last Modified:

jquery search for and replace text

I am looking for something i can do in jquery to search through for a certain word and change it into a link with the same word

for example lets say i have this div

<div>
We all know alot about doctors but dr. thomasson is an especially good one.

</div>

I want some how to look for 'thomasson' and change it too a href link so it looks like
<a href="#">thomasson</a>

Please help
0
Brant Snow
Asked:
Brant Snow
1 Solution
 
leakim971PluritechnicianCommented:
check this : http://jsfiddle.net/Pc7En/

    var lookingFor = "thomasson";
    $("div").html( $("div").text().replace(new RegExp("(" + lookingFor + ")","g"), "<a href='http://tinyurl.com/c5vwwll'>$1</a>") );

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now