I have a contentEditable div which in some cases replaces text with images. It works but when it replaces specific text with an image the div lose focus, and I can’t write anything in, how to make it to work?
obj.onfocus = function() {Replace(this)};
obj.onblur = function() {Replace(this)};
obj.onkeyup = function() {Replace(this)};
obj.onkeydown = function() {Replace(this)};
obj.onclick = function() {Replace(this)};
function Replace(element)
{
element.innerHTML = element.innerHTML.replace(/some_text/gi, '<img src="image.." />')
}
contentEditableareas seem to be buggy when replacing the innerHTML with actual HTML elements directly. Instead, you’ll have to do low-level node replacement with a created element:See demo