var replaced = inner.replace(match, "<span style=\"background-color:yellow; font-weight:bold;\">" + lastMatch + "</span>"); document.getElementById("txt").innerHTML = replaced;