javascript - Why is DOM copied when I press enter key on the end of content in ContentEditable? -
while i'm making web editor contenteditable, met strange action.
if press enter key in contenteditable element, current line's dom copied next line. , press enter key again, dom copied again. situation occur when caret end of content. text content not occur way. produced situation on latest chrome browser.
<div id="editor" contenteditable="true" style="border:1px solid #000; width:500px; height:200px;"> <p><span class="name">content</span></p> </div> <div id="before" style="border:1px solid blue; width:500px; height:100px;"></div> <div id="afterenterkeypressed" style="border:1px solid red; width:500px; height:100px;"></div> $('#editor').on('keyup', function(e) { var keycode = e.keycode; if (keycode === 13) { $('#afterenterkeypressed').text($('#editor').html()); } }); $('#before').text($('#editor').html());
here demo: https://jsfiddle.net/qgpcdtpe/1/
Comments
Post a Comment