574558-1.xhtml (738B)
1 <html xmlns="http://www.w3.org/1999/xhtml"><head><script> 2 <![CDATA[ 3 function onLoad() { 4 // For emulating the traditional behavior, collapse Selection to end of the 5 // text node in the <textarea> which is the deepest last child of the <body>. 6 const textarea = document.querySelector("textarea"); 7 getSelection().collapse(textarea.lastChild, textarea.lastChild.length); 8 document.execCommand("selectAll"); 9 document.execCommand("selectAll"); 10 document.execCommand("inserthtml", false, "<span><div>"); 11 const span = document.createElementNS("http://www.w3.org/1999/xhtml", "span"); 12 textarea.appendChild(span); 13 } 14 ]]> 15 </script></head><div contenteditable="true"></div><body onload="onLoad();"><textarea>f</textarea></body></html>