Add the userName to the h2 tag - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Heading

Description

Add the userName to the h2 tag

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  ww  w . j  a v a 2  s .  co m
var h = document.querySelector('h2');
var userName "Please enter name";
h.innerHTML = h.innerHTML + ' / ' + userName
    }

      </script> 
   </head> 
   <body> 
      <h2> H2 Text </h2>  
   </body>
</html>

Related Tutorials