Append li with a link with a custom click event - Javascript jQuery

Javascript examples for jQuery:Link

Description

Append li with a link with a custom 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://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){//  w  w w  .  ja  v  a2s  .  c o  m
$('#myid ul').append("<li><a href=''>Link</a></li>");
$("a").live("click", function() {
    console.log('hi');
});
    });

      </script> 
 </head> 
 <body> 
  <div id="myid"> 
   <ul></ul> 
  </div>  
 </body>
</html>

Related Tutorials