Focus editable div - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Div

Description

Focus editable div

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//from   w w w.ja va2s .c om

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>

Related Tutorials