How to remove a column from a table using JQuery

Sometimes you may get requirement to remove a column from a table or you may want to hide a column from a table. In both cases the logic is same just we have to use the .remove() method if we are interested to remove the column or use the .hide() method if we are interested to hide the column. Let’s have a look on how to do so
Row 2 Cell 1 Row 2 Cell 2
Row 3 Cell 1 Row 3 Cell 2
I want to remove the whole column whenever user click on Remove Button image, let see how we can do this in JQuery
$("#removeButton ").click(function() {
    var $td = $(this).closest("td");
    var index = $td.index() + 1;
    $td.closest("table").find("td:nth-child(" + index + ")").remove();
});
Hopefully it will work for you.

0 comments: