Onimax
Onimax

Reputation: 107

Remove table element inside parent TD Jquery

I'm struggling to remove the table element inside the TD tag using jQuery.

Here is my Table structure:

<table>
   <tr>
       <td>some data</td>
       <td>
       <table><tr><td>this table inside I want to delete</td></tr></table>
       </td>
   </tr>
</table>

I want to use .remove() function in ready state function, but I don't know how.

Upvotes: 1

Views: 8856

Answers (6)

Somnath Kharat
Somnath Kharat

Reputation: 3610

U can also use empty

$('td table').empty();

DEMO

Difference between using remove and empty

Upvotes: 0

Sandeep
Sandeep

Reputation: 69

$('td > table').remove();

this will only remove direct child of parent.

Upvotes: 0

S. S. Rawat
S. S. Rawat

Reputation: 6111

This will help you, here eq() are used to define which td you want to remove...

$('td').eq(0).find('table').remove();

Demo here

Upvotes: 0

Hussein Nazzal
Hussein Nazzal

Reputation: 2557

i suppose the following will work :

$('td table').remove()

basically what this says is :

select the table , which is a child of a td .

so no matter how many tables in td's you have it will remove them all .

use an id or class name to furthermore define what you want to select .

Upvotes: 4

Kiranramchandran
Kiranramchandran

Reputation: 2094

try this

$(document).ready(function(){
     $('td table').remove();
});

Upvotes: 1

Alex
Alex

Reputation: 23300

Give your table an Id like this

<table>
   <tr>
       <td>some data</td>
       <td>
       <table id="tableId"><tr><td>this table inside I want to delete</td></tr></table>
       </td>
   </tr>
</table>

Then you can pinpoint accurately your selector

$('#tableId').remove()

Upvotes: 0

Related Questions