Handle button click event and display value attribute - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Button

Description

Handle button click event and display value attribute

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(){/*  w w w .  j a  v a  2 s.co m*/
    var buttons = document.getElementsByTagName('button');
    for (i = 0; i < buttons.length; i++) {
        buttons[i].addEventListener('click', function () {
            console.log(this.value);
        }, false)
    }
}

      </script> 
   </head> 
   <body> 
      <button value="yes">Yes</button> 
      <button value="no">No</button>  
   </body>
</html>

Related Tutorials