Solved

jquery search for and replace text

Posted on 2012-04-13
1
280 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
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).

821 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