766387.html (694B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <script> 5 function onLoad() { 6 const editingHost = document.querySelectorAll("div[contenteditable]"); 7 // For emulating the traditional behavior, collapse Selection to end of the 8 // last <div contenteditable> which is the deepest last child of the <body>. 9 getSelection().collapse(editingHost[1], editingHost[1].childNodes.length); 10 getSelection().removeAllRanges(); 11 const r = document.createRange(); 12 r.setStart(editingHost[0], 1); 13 r.setEnd(editingHost[1], 0); 14 getSelection().addRange(r); 15 document.execCommand("insertOrderedList"); 16 } 17 </script> 18 </head> 19 20 <body onload="onLoad();"><div contenteditable>a</div><div contenteditable></div></body> 21 </html>