Update and change <p> element text in button action - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Paragraph

Description

Update and change <p> element text in button action

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <p id="p1">Hello</p> 
      <br> 
      <button onclick="ChangeText()">Button</button> 
      <script>
            var p1 = document.getElementById("p1");
            function ChangeText () {
                p1.innerHTML = "Changed text on button click!";
            }//  www  . j  a  va  2 s .  c  o m
         
      </script>  
   </body>
</html>

Related Tutorials