Simple jQuery code to Hide/Show a column in Listview/Table


Below jQuery code helps to hide/unhide a column in a table.

if (document.getElementById("tblUpgradePaths")) {
    $("#tblID > TBODY > TR").each(function () {
    if ($(this).children("TD").length > 1)
          $(this).children("TD:last").css("display", "none"); // To hide last column

          //$(this).children("TD:nth-col(4)").css("display", "none");  //To hide 4th column
     });

}
Use selector TD:last to select last column or use jQuery nth column selector to select nth column. Hope this helps someone!