make a div element editable like a textarea when clicking it - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Textarea

Description

make a div element editable like a textarea when clicking it

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <div id="myP">
         This is a paragraph. Click the button to make me editable.
      </div> 
      <button onclick="myFunction()">Try it</button> 
      <p id="demo"></p> 
      <script>
    function myFunction() {/* ww w.j  av a  2s  . c o  m*/
        document.getElementById("myP").contentEditable = true;
        document.getElementById("demo").innerHTML = "The p element above is now editable. Try to change its text.";
    }
    
      </script>  
   </body>
</html>

Related Tutorials