Accessing a variable in a different function - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:attr

Description

Accessing a variable in a different function

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-3.1.1.slim.min.js"></script> 
  <script type="text/javascript">
    window.onload=function(){//from ww  w .jav a 2s  .  c om
var folderid;
$(".loadlist").click(function() {
     folderid =jQuery(this).attr('id') || '';
     showId();
});
function showId() {
   console.log(folderid);
}
    }

      </script> 
 </head> 
 <body> 
  <div class="loadlist" id="1">
    asdf
  </div>  
 </body>
</html>

Related Tutorials