title: JQuery .on() isn't binding click events to dynamically created elements
body: <p>I have a textbox that dynamically adds an element when I press enter, and another that deletes the element when I click the delete button. The delete method works for any existing elements, but doesn't work for any elements that were dynamically inserted.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>$ -&gt;
      # AJAX to add a new stock
      $("#add-symbol").keypress (e) -&gt;
          if e.which == 13
              url = $(this).data('url')
              name = $(this).val()
              $.ajax
                  url: url
                  type: "POST"
                  data: {
                      user_id: $('#info').data('user-id'),
                      name: name
                  }
                  success: (response) -&gt;
                      if response.status == 200
                          new_element = '&lt;a class="item" data-path="' + response.path + '" data-stock="' + response.symbol + '"&gt;'+ response.symbol + '&lt;i class="icon remove"&gt;&lt;/i&gt;&lt;/a&gt;'
                          $('#symbols').append(new_element)
                          $('#add-symbol').val('')
                      else
                       #deal with errors
  
      # AJAX to delete stocks
      $('.icon.remove').on('click', (e) -&gt;
          console.log('click click')
          $parent = $($(this).parent().get(0))
          stock = $parent.data('stock')
          user_id = $("#info").data('user-id')
          url = $parent.data('path')
  
          $.ajax
              url: url
              type: "DELETE"
              data: {
                  user_id: user_id,
                  name: stock
              }
              success: (response) -&gt;
                  if response.status == 200
                      $parent.remove()
                  else
                      # deal with errors
      )
  </code></pre>
  
  <p>Any ideas? From what I've read, .on() should fix the issue of binding a click event to a dynamically generated element, but it doesn't seem to be working.</p>