Set the global variable in click event - Javascript jQuery

Javascript examples for jQuery:Mouse Event

Description

Set the global variable in click event

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-compat-git.js"></script> 
  <script type="text/javascript">
    $(window).on('load', function() {
$(document).ready(function() {
    var x = "";
    $("#my").click(function() {
        x = "test";
        console.log(x);
    });/*ww  w.j av  a2  s.  c  om*/
    console.log(x);
});
    });

      </script> 
 </head> 
 <body> 
  <button id="my">hihi</button>  
 </body>
</html>

Related Tutorials