Simple onclick event to output String - Javascript DOM

Javascript examples for DOM:Event


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

      <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";

      <button onclick="myFunction()">Click me</button> 
      <p id="demo"></p>  

Related Tutorials