BentCoder
BentCoder

Reputation: 12740

Cloning and removing the current table

I'm trying to remove the table which was cloned but removing only works for the first table not the current one.

I used these two codes but no luck.

$(this).closest('table').remove();
$(this).parent().parent().remove();

My intent is to make REMOVE span hidden at the beginning and make it visible for only cloned tables so that user cannot remove the first table and have something to be cloned. If you can help me achieving it as well then I'll be happier.

So far this is what I've done with my very little jquery knowledge: http://jsfiddle.net/sZwvd/1/

Thanks in advance

Upvotes: 1

Views: 48

Answers (1)

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67207

Try to use event-delegation on dynamically created elements,

$('div').on('click','.remove-table', function(event) {
   event.preventDefault();  
   $(this).closest('table').remove();
});

DEMO

Upvotes: 3

Related Questions