I am trying to append a li element to a list with a link that has custom click event… I am trying something like:
<div id="myid"><ul></ul></div>
$('#myid ul').append("<li><a href=''>Link</a></li>").click(function(){alert('hi')})
But the click event is on the li and not the a href. How do I fix this?
Actually, the click event handler is bound to the
ulelement.Bind it to the
aelement:DEMO
Creating the link separately might be cleaner though:
Information about the methods used can be found in the jQuery API documentation.