Ehsan Mahpour’s Weblog

Highlighting a text in a HTML page

by mahpour on Nov.14, 2006, under HTML/CSS Tips

Here is the javascript code which should be used somewhere on the bottom of html page (of course inside the script tags)

just replace "text_to_find" with your text (it could be a variable or a serverside string) without quotes. Also change CONTAINER_TAG_ID with the container id and enjoy.

document.getElementById("CONTAINER_TAG_ID").innerHTML= document.getElementById("CONTAINER_TAG_ID").innerHTML.replace(/(text_to_find)/gi,"< span style='background-color:yellow;'>$1< /span >");

Leave a Reply

You must be logged in to post a comment.

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...