Calling an alert function from a button but without using onclick - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Button

Description

Calling an alert function from a button but without using onclick

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  w w w .j a v  a 2  s.  c o  m*/
document.getElementById("test").onclick = Hello;
function Hello(){
    console.log("Hello");
}
    }

      </script> 
   </head> 
   <body> 
      <button type="button" id="test"> Click me! </button>  
   </body>
</html>

Related Tutorials