Firefox doesn't seem to focus on the paragraph inside contenteditable. I tried to set the focus programmatically. The chromes seem to do the magic, and everything works fine.
<h2 contenteditable="true">Some text</h2><br/><br/> <div contenteditable="true"> <p id="test">Paragraph text</p> </div>
- Press h2 and click the tab
- start of input - text is not displayed inside P.
JSFiddle - http://jsfiddle.net/THPmr/126/
$( "#test" ).focus(function() { $( "<span>Focused!</span>" ).appendTo( "body" ).fadeOut( 1000 ); }); $("#before").on('keydown', function(e){ if(e.which == 9){ $('#test').triggerHandler('focus'); } }); $("#test").bind( "focus", function() { $("#test").css('background', 'yellow'); });
I also tried to set the carriage position, but it does not work in firefox, it works in chrome
JSFiddle - http://jsfiddle.net/vXnCM/2998/
function setCaret() { var el = document.getElementById("test"); var range = document.createRange(); var sel = window.getSelection(); range.setStart(el, 0); range.collapse(true); sel.removeAllRanges(); sel.addRange(range); el.focus(); }
Thank you in advance
source share