How can I remove a td
cell in a table with MVC4?
Could I use JQuery or JavaScript? And if so, how?
<table class="table table-striped table-bordered table-hover" id="tblParticipantList">
<thead>
<tr>
<th>Name</th>
<th>Adress</th>
<th>Redeem Code</th>
</tr>
</thead>
<tbody>
<tr data-id="columnId" id="customerPartial_94">
<td data-field="NAME">Attn Donna</td>
<td data-field="ADDRESS">3046 Lavon Drive Newyork America 7504</td>
<td data-field="SECURITY_REDEMPTION_CD"></td>
</tr>
<tr data-id="columnId" id="customerPartial_95">
<td data-field="NAME">F 1 La 1</td>
<td data-field="ADDRESS">Asd 1 s 1 Ci 1 s</td>
<td data-field="SECURITY_REDEMPTION_CD"></td>
</tr>
</tbody>
</table>
jQuery: Code to Remove Table Row (tr) on Button Click. Here, we make a jQuery click event on the button tag. Using the closest() method we select the current row ie closest tr of our delete button, and then with the remove() method will delete that record. Similarly for deleting the next row tr we use .
The remove() method is used to remove the table row from an HTML table using JavaScript. remove() Method: This method removes the selected elements alongwith text and child nodes. This method also removes data and events of the selected elements.
The deleteCell() method deletes a cell in the current table row. Tip: Use the insertCell() method to insert a cell in the current table row.
To remove TD item, you should know exactly td what you want to remove.
Remove All TD item
$('#tblParticipantList > tr > td').remove();
Remove TD at specified Row
$('#tblParticipantList > tr').eq(rowNum).children('td').remove();
Remove TD at specified Row and Column
$('#tblParticipantList > tr').eq(rowNum).children('td').eq(colNum).remove();
Remove child td
of the position you want using eq()
. Use proper id and class in the selector for expected result.
$('.table-striped tr').each(function(){
$(this).children('td').eq(3).remove();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With