Learn JavaScript Part 7: getElementById() Method

getElementById method is used to get the element with the specified id.
  1. <!DOCTYPE html>  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4.     <title></title>  
  5. </head>  
  6. <body>  
  7.     <div id="message">  
  8.         Hello  
  9.     </div>  
  10.   
  11.     <script id="javascript">  
  12.   
  13.     var name = prompt("Enter Your Name","");  
  14.   
  15.     document.getElementById('message').innerHTML += name;  
  16.   
  17.     </script>  
  18. </body>  
  19. </html> 

User Input

Enter Your Name?

Akshay

Output

Hello Akshay