Solved

jquery search for and replace text

Posted on 2012-04-13
1
281 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
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…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

739 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