Simple onclick event to output String - Javascript DOM

Javascript examples for DOM:Event

Introduction

Click the button to trigger a function that will output "Hello World" in a p element with id="demo".

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
function myFunction() {//from w ww. j a va 2  s  .  c o  m
    document.getElementById("demo").innerHTML = "Hello World";
}

      </script> 
   </head> 
   <body> 
      
      <button onclick="myFunction()">Click me</button> 
      <p id="demo"></p>  
   </body>
</html>

Related Tutorials