Solved

jquery search for and replace text

Posted on 2012-04-13
1
277 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
Comment Utility
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 to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

744 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

16 Experts available now in Live!

Get 1:1 Help Now