Javascript examples for jQuery Method and Property:attr
Accessing a variable in a different function
<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>