I need to model the search and replace function on my webpage using javascript, regardless of the search and replace, but the problem is how to highlight matching search results inside textArea before replacing them. I tried replacing the consistent results with a Bold Tag, but it does not work because textArea does not understand HTML tags.
I used the following code:
function findMyText(searchTxt) { var textAreaTxt = ""; textAreaTxt = document.getElementById("myTxtAreaID").value; var match = new RegExp(searchTxt, "ig"); var boldText = '<B>' + searchTxt+ '<\/B>'; var replaced = textAreaTxt .replace(match, boldText); document.getElementById("myTxtAreaID").value= replaced; }
is there any other way to highlight search results in textArea or how to make textArea understand HTML tags
Thanks in advance
source share