Reputation: 586
I am using a table and dynamically creating a column (td) on click jquery. I want to remove the column as the last td, but in each td one more table is coming, hence I can't remove the entire td.
<table width="100%" border="0">
<tr>
<td class="myclass">
<table width="100%" border="0">
<tr>
<td> </td>
</tr>
</table>
</td>
<td class="myclass">
<table width="100%" border="0">
<tr>
<td> </td>
</tr>
</table>
</td>
</tr>
</table>
I want to remove the last td having the class name my class. I tried like this:
$('tr').find('td:last').remove();
But it's removing the last td from the inner table, I want to remove the entire last td having class myclass.
Upvotes: 0
Views: 1811
Reputation: 115272
Get td
with the class
$('tr > td.myClass:last-child').remove();
or if you want t remove the last one from the collection
$('td.myClass:last').remove();
Upvotes: 0
Reputation: 10292
You can select specific td
with .myclass
$("td.myclass:last").remove();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table width="100%" border="0">
<tr>
<td class="myclass">
<table width="100%" border="0">
<tr>
<td> First</td>
</tr>
</table>
</td>
<td class="myclass">
<table width="100%" border="0">
<tr>
<td> Last</td>
</tr>
</table>
</td>
</tr>
</table>
Upvotes: 0