I am attempting to highlight words in a textarea by placing a div
behind the field and transferring the values over.
$("div").html($("textarea").text()
.replace("bad-word", "<span style='background-color: red'>bad-word</span>"))
My test worked perfectly in Chrome, but I encountered an issue in IE where span
s would not break to the next line within the div
if the word was too long to fit on a single row. Instead, it caused a break-word effect which did not align properly with the text in the textarea. This problem occurred in both IE8 and IE9.
Screenshot of code result in IE 9
If you visit this fiddle link and add a letter at the start of the textarea, you will see the issue firsthand.