Highlighting a text in a HTML page

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 comment

Please be polite and on topic. Your e-mail will never be published.

You must be logged in to post a comment.