Add button click event handler - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Button

Description

Add button click event handler

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <h1 id="myid"> what can javascript Do?</h1> 
      <p id="demo">Javascript can change html content.</p> 
      <button type="button" onclick="myFunction()"> Click Me!</button> 
      <script type="text/javascript">
        function myFunction() {/*from  ww w.ja  va  2  s .co m*/
            document.getElementById('demo').innerHTML = 'hello javascript';
        }
        
      </script>  
   </body>
</html>

Related Tutorials