If have this code here:
$(function() {
$("#a").keyup(function(e) {
var updatedText = this.value.replace(
/(^|[^>])(hello)($|[^<])/gi, "$1<b>$2</b>$3");
if (updatedText != this.value)
this.value = updatedText;
});
});
It functions as to take the last word typed that matches the RegExp (in this case the word hello) and adds <b>
tags around it. This works great in a Textarea (demo here: http://jsbin.com/ibecel/2/edit
But I cannot seem to modify it to work in a contenteditable div. How would I need to modify it to work in a contenteditable div? I tried changing the value
object to innerHTML
and innerText
but to no avail. It always looses focus after the word is typed, or doesn't exit the new things made. PLEASE HELP