Coder Perfect

What is the best jQuery method for removing a table row?


What is the best jQuery approach for removing a table row?

Asked by Darryl Hein

Solution #1

You’re right:


If you have an id for your row, such as:

<tr id="myTableRow"><td>blah</td></tr>

If you don’t have an id, any of jQuery’s selectors will suffice.

Answered by imjoevasquez

Solution #2

$('#myTable tr').click(function(){
    return false;

One that is even better

$("#MyTable").on("click", "#DeleteButton", function() {

Answered by nickf

Solution #3

Assuming you have a button/link inside a table data cell, something like this will suffice…

$(".delete").live('click', function(event) {

This will delete the parent of the parent of the clicked button/link. You need to use parent() twice because the button is inside a data cell, which is inside a row….which is what you want to delete. It’s a jQuery object, not a standard DOM object, therefore you need to use parent() twice. Because $(this) is the clicked button, having something like this will merely delete the button:


While doing so, the following data cell will be removed:


Something like this would work if you just want to remove a row by clicking anywhere on it. This may simply be changed to prompt the user or only work when double-clicked:

$(".delete").live('click', function(event) {

I hope this information is useful… I had some difficulty with this as well.

Answered by sluther

Solution #4

You can use:


for locating an element’s parent table row

It’s more refined than being a parent (). parent(), which is what I started with and quickly realized was a mistake.

—Revise — The question, it was pointed out, was about eliminating the row…


You can just do what is outlined below:


A code snippet like this can be used for a variety of tasks, such as firing events on numerous items.

Answered by Ian Lewis

Solution #5

Easy.. Try this

$("table td img.delete").click(function () {
    $(this).parent().parent().parent().fadeTo(400, 0, function () { 
    return false;

Answered by Thurein

Post is based on