Javascript examples for DOM HTML Element:Div
Javascript set caret position in a ContentEditable div
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){/* w w w. ja v a 2 s. c o m*/ var sel = window.getSelection(); var innerDiv = document.getElementById("innerKey"); var innerDivText = innerDiv.firstChild; sel.collapse(innerDivText, 0); innerDiv.parentNode.focus(); } </script> </head> <body> <div contenteditable="true" class="key"> <div id="innerKey"> 276 </div> </div> </body> </html>