Delete parent element itself in jquery

JQuery

$('#imgDelete').live('click', function() { $(this).parent('td').remove(); }); 

All <td> generated programmatically and bound. imgDelete also bound internally for each <td> . But the above code should not remove the parent. Dynamically generate columns cannot be deleted or I missed something. Thank you

+4
source share
1 answer

Try:

  $('#imgDelete').live('click', function() { $(this).parents('td').remove(); }); 

Find the difference between .parent () and .parents ();) (I assume imgDelete is not a direct child of td) (Also, you should use the class instead of id, as was said)

+1
source

Source: https://habr.com/ru/post/1380576/


All Articles