Create a function and assign to onclick event handler for button - Javascript DOM Event

Javascript examples for DOM Event:onclick

Description

Create a function and assign to onclick event handler for button

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Example</title> 
      <script type="text/javascript">
    function saysomething()//from w ww .j  a v a2s. c  o  m
    {
        console.log("I am 29 years old");
    }
    function displayatts()
    {
        document.getElementById("buttonone").onclick = saysomething;
    }

      </script> 
   </head>
   <body onload="displayatts();"> 
      <input type="button" id="buttonone" value="me">   
   </body>
</html>

Related Tutorials