I have a simple snippet of code that injects an element into a contenteditable and places the user's cursor inside it. It works well in every modern browser except Firefox. Any ideas on why this isn't working (any help appreciated)?
Live demo at CodePen: http://codepen.io/ashblue/pen/slwJu
function forceInjectAndFocus () {
var range = document.createRange();
var sel = window.getSelection();
var child = $('#editor').html('<p class="test">a</p>').children().first().get(0);
range.setStart(child.firstChild, 0);
sel.removeAllRanges();
sel.addRange(range);
$(child.firstChild).detach();
}
tag when you type.
– Ash Blue Apr 28 '14 at 19:27`.
– Tim Down Apr 28 '14 at 22:46