pri_dev pri_dev - 4 months ago 7
jQuery Question

remove a column from the row

This may be a basic question... but I am a newbie to jquery.
I need to remove the last column from a table row below

var ptr = $(this).closest("tr")

ptr.remove("td :last")


Is this the way to do it?

Answer
  1. If you want to remove the last cell in each row (the whole column)

    You can do the following

    var ptr = $("#myTable").find("tr");
    ptr.find("td:last").remove();
    

    jsFiddle Demonstration

  2. If you only want to remove the last cell in the first row do this

    var ptr = $("#myTable").find("tr:first");
    ptr.find("td:last").remove();
    

    jsFiddle Demonstration

Anyway, i dont know how your table is structured (no source in your question). You should use thead and tbody for search engine optimization and good html.

<table id="myTable">
    <thead>
        <tr>
           <td>first column</td>
           <td>second column</td>
        </tr>
    </thead>

    <tbody>
         <tr>
           <td>first cell first row</td>
           <td>second cell first column</td>
        </tr>  
        <tr>
           <td>first cell second row</td>
           <td>second cell second column</td>
        </tr> 
    </tbody>        
</table>