Click event defined in the jquery ready on new element
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/13384588/dynamically-adding-elements-and-trying-to-use-the-selectors-click-event-jquery">Dynamically Adding Elements and trying to use the selectors .click event Jquery</a>  </p>
</blockquote>



<pre><code>$(function(){
  $('a.bar').click(function(){
    // do something
  });

  $('a.foo').click(function(){
    $('#toto').append('&lt;a class="bar"&gt;bar&lt;/a&gt;');
  });
});


 &lt;a class="foo"&gt;foo&lt;/a&gt;
 &lt;div id="toto"&gt;&lt;/div&gt;
</code></pre>

<p>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 <code>a.foo</code> for <code>a.bar</code>)?</p>
