Click function was executed every time the document is loaded - Javascript jQuery

Javascript examples for jQuery:Document

Description

Click function was executed every time the document is loaded

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.1.3.js"></script> 
  <script type="text/javascript">
    $(function(){//w  w  w  . j  a  v a  2 s  .c o  m
for(var c=1; c<=5; c++){
    var btn = $("<button>Button "+c+"</button>");
    btn.on('click', function(){
        console.log("You click button "+c);
    });
    $("body").append(btn);
}
    });

      </script> 
 </head> 
 <body>  
 </body>
</html>

Related Tutorials