I'm trying to find every occurrence of a string within a string, and replace it with
<span class="blue_color_text">matched_string</span>
This is what I'm using (found it here in one of the questions):
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};
Here's the actual implemention:
function showResult(str)
{
if (str.length == 0)
{
return;
}
if (window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
xmlhttp.onreadystatechange = function() {
var e = document.getElementById("res_ls");
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
xmlhttp.responseText.replaceAll(search_string.value, "<span class=\"green\">"+search_string.value+"</span>");
e.innerHTML = xmlhttp.responseText;
e.removeAttribute("class");
}
}
xmlhttp.open("GET","ajax.php?s="+str, true);
xmlhttp.send();
}
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};
Nothing is actually changing. Any idea why?