Possible Duplicate:
Dynamically Adding Elements and trying to use the selectors .click event Jquery
$(function(){
$('a.bar').click(function(){
// do something
});
$('a.foo').click(function(){
$('#toto').append('<a class="bar">bar</a>');
});
});
<a class="foo">foo</a>
<div id="toto"></div>
How to automatically attach the click event defined in the JQuery ready for a dom element that was added by an other event (for instance by clicking on a.foo for a.bar)?
What you need is the delegated event technique.. See below using
.on