Show source code of HTML element on click to form input - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Text

Description

Show source code of HTML element on click to form input

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body>   
      <script type="text/javascript">
function showSourceCode(toShow){// www .jav a2  s. c  o  m
    sourceCode.value = toShow.innerHTML;
}

      </script> 
      <p onclick="showSourceCode(this);"> 
         <b>Show source code when this text is clicked!</b> 
      </p> 
      <p onclick="showSourceCode(this)">
         <i>show source code on click!</i>
      </p> 
      <input type="text" id="sourceCode">    
   </body>
</html>

Related Tutorials