I've written a basic function that searches in DIV's for text and makes the div visible if a match is found (they're all hidden by default). Now, what I want to do is make the matching text bold by wrapping it in <B> tags. But I can't seem to get it right. Here's what I've got so far:
I've used an alert where I've commented out searchResult above to tell me what it's value is, and it does equal what's contained in the DIV. For the moment I was just trying to change it to "test" until I get it working, but it doesn't work. Can anbydoy help me out at all?
Code:
function doMySearch()
{
var searchObj2 = document.forms['search'].elements['searchString'].value;
var searchString = new RegExp(searchObj2,"i");
var myArray = document.getElementsByTagName("div");
for(var i = 0; i < myArray.length; i++)
{
var searchText = myArray[i].innerText;
//alert(searchString);
var searchResult = searchText.match(searchString);
if(searchResult)
{
//searchResult.replace("test");
myArray[i].style.display='block';
} else {
myArray[i].style.display='none';
}
}
}