Add event to new added element in jQuery - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:on

Description

Add event to new added element 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-1.8.3.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){/*from   w  ww.j a  v a2s .  c  o m*/
$('a').on('click', function() {
    var newel = '<input type="text" />';
    $(newel).on("focus",function() { console.log("hello")}).insertAfter($('a'));
});
    });

      </script> 
 </head> 
 <body> 
  <a href="#">ee</a>  
 </body>
</html>

Related Tutorials