Johan
Johan

Reputation: 35194

trouble removing element using remove()

Im having some trouble removing part of a cloned element:

console.log($(this).closest('tr').clone().find('td:last')); //this is the td that i want to remove
            $(this).closest('tr').clone().remove('td:last').append('<td><input type="button" value="Del" class="removesystem"/></td>').appendTo('.targetbox table'); //doesnt get removed here. i tried with .end() after remove() as well, without any success.

Have i missed something? Thanks

Upvotes: 0

Views: 97

Answers (3)

max4ever
max4ever

Reputation: 12142

Delete a clone? Append to a deleted object?

$(this).closest('tr').find('td:last').remove();

Upvotes: 0

Kristoffer Sall-Storgaard
Kristoffer Sall-Storgaard

Reputation: 10636

Remove only works on selected elements see the documentation: http://api.jquery.com/remove/

Select the correct element and remove it:

$(this).closest('tr').clone().find('td:last').remove().end().append( yadda yadda yadda )

Upvotes: 1

Val
Val

Reputation: 17522

I think .remove(/*filters*/) accespts only filters, of the selected elements,

so you should do this.

$(this).closest('tr').clone().find('td:last');

$(this).closest('tr').clone().find('td').remove(':last').append('<td><input type="button" value="Del" class="removesystem"/></td>').appendTo('.targetbox table');

also remove console.log(); as it may not work, if console is not open

Upvotes: 0

Related Questions