Search code examples
jqueryshow-hide

Hide a table column using jQuery


I am trying to hide a table column of a table with jQuery but am not really sure on how to do it. I have a drop down for each column and have two options, hide and show, on hide I would like column 0 to be hidden using the .hide() function I presume, and also shown when show is selected?


Solution

  • The :nth-child pseudo-selector selects elements based on their position. If you want to select the, say, 5th column, you can use $("td:nth-child(5)").

    An implementation could look like:

    $("#mytable td:nth-child(5)").hide(); //or .hide(), or .toggle()