If you are ready to use jQuery then it is easier:
var searchPattern = new RegExp(searchString, 'g');
$elem.html($elem.html().replace(searchPattern, "<ACRONYM class='srch'>" + searchString + "</ACRONYM>"));
Where, $elem
is the jQuery object for the HTML element you are searching in. For example, if it is a particular div like <div id='me'>some text</div>
and you are searching for text "some", then it will be like this:
var searchPattern = new RegExp('some', 'g');
$elem = $('#me');
$elem.html($elem.html().replace(searchPattern, "<ACRONYM class='srch'>" + searchString + "</ACRONYM>"));
Give appropriate highlight style for the css class 'srch'. Do not forget to remove the 'acronym' element with 'srch' class once your searching is over.