I have a contenteditable div
. I am trying to hunt for the word "design" and wrap it in a span
element.
HTML:
<div id="text"></div>
JavaScript:
$("#text").prop("contenteditable", true);
var string = $("#text")[0].innerHTML;
$("#text").innerHTML = string.replace("design", "<span>design</span>");
This doesn't work. My first guess would be that its because the script runs once, so by the time I type "design" it doesn't catch it. So, I tried putting it in a setInterval
, but that didn't work either. JSFiddle
Any help would be much appreciated.