Solved

jquery search for and replace text

Posted on 2012-04-13
1
278 Views
Last Modified: 2012-04-13
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
Comment
Question by:Brant Snow
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 37843994
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now