title: Event handlers on dynamically created elements?
body: <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(document).ready(function () {
  
     $('.add-button').on('click', function () {
    
        $('.alert-button').after('&lt;button type="button" class="alert-button"&gt;Click me! &lt;/button&gt;&lt;br&gt;');
    
    });
    
  
    $('.alert-button').on('click', function () {
    
      alert('HI!');
    
    });
  
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;button type='button' class="alert-button"&gt;Click me! &lt;/button&gt;&lt;br&gt;
  &lt;button type="button" class="add-button"&gt;Add button!&lt;/button&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Hi! My " $('.alert-button').on('click'..." code works on elements created on page load, but not on dinamically created ones.</p>
  
  <p>So i have a page with 2 buttons (please run the snippet above). If you click on "Click me!" alert "Hi!" appears. </p>
  
  <p>But when I duplicate "Click me!" button via pressing "Add button", a click on the duplicated "Click me!" produces no alert "Hi!" (although it also has ".alert-button" class).</p>
  
  <p>I want to see alert "Hi!" when I click on any "Click me!" button. </p>
  
  <p>what am I doin' wrong?:)</p>