Store the value of a button on click event in jQuery - Javascript jQuery

Javascript examples for jQuery:Form Button

Description

Store the value of a button on click event in jQuery

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://code.jquery.com/jquery-2.0.2.js"></script> 
  <script type="text/javascript">
    $(function(){//  w  w w  .jav  a2  s  . com
$('button').on('click', function() {
    var colour = $.trim( $(this).html() );
    console.log("You have chosen " + colour);
});
    });

      </script> 
 </head> 
 <body> 
  <button> red </button> 
  <button> blue </button> 
  <button> yellow </button>  
 </body>
</html>

Related Tutorials