Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove td in table

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>
like image 471
Lam Son Avatar asked Jul 17 '15 04:07

Lam Son


People also ask

How to remove tr on Click?

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 .

How to remove tr from table using JavaScript?

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.

How to remove cells in Html?

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.


2 Answers

To remove TD item, you should know exactly td what you want to remove.

  1. Remove All TD item

    $('#tblParticipantList > tr > td').remove();
    
  2. Remove TD at specified Row

    $('#tblParticipantList > tr').eq(rowNum).children('td').remove();
    
  3. Remove TD at specified Row and Column

    $('#tblParticipantList > tr').eq(rowNum).children('td').eq(colNum).remove();
    
like image 102
Luc Avatar answered Oct 16 '22 11:10

Luc


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();
});
like image 5
rrk Avatar answered Oct 16 '22 11:10

rrk