-1

My function:

jQuery('#allForms td.edit').click(function(e){
    e.preventDefault();
    addTextBox(jQuery(this));
});

doesn't work for new elements which I'm creating in this way:

var output = '<tr><td class="edit">'+values[0]+
    '</td><td class="edit">'+values[1]+
    '</td><td class="edit">'+values[2]+
    '</td><td class="edit">'+values[3]+
    '</td><td><a href="#" class="deleteForm">USUŃ</a></td></tr>';
formsList.find('tr:last').after(output);
addForm.find("input").val('');

When I click at newly added element nothing happens. When I click at elements which was loaded with website all works good.

2 Answers2

0

You need to use event delegation for attaching events to dynamically added elements:

jQuery('#allForms').on('click','td.edit',function(e){
e.preventDefault();
addTextBox(jQuery(this));
});
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
0

You need to try this

jQuery(document).on("click", '#allForms td.edit', function(e){
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331