Remove n’th table column - jQuery plugin

My usual short Friday post. Today I would like to share with you a new utility I wrote to work with HTML tables. We already have jQuery functions to add table row, remove table row (on user click), add table row number plugin and now here is jQuery code to remove table column.

jQuery utility to remove table’s n’th column:

$.fn.removeCol = function(col){
    // Make sure col has value
    if(!col){ col = 1; }
    $('tr td:nth-child('+col+'), tr th:nth-child('+col+')', this).remove();
    return this;

Just add this code to your javascript file and use it in your jQuery code like this:

// Remove all table's second columns

// Remove table's first column (default)

The function takes column number to delete as an argument and removes that column. If you don’t supply any column number it removes the first table column by default.