title: Hide table column with jQuery
body: <p>This was asked many times, I know but this is different! I made this:</p>
  
  <p><img src="https://i.stack.imgur.com/4dyRR.png" alt="enter image description here"></p>
  
  <p>When you click on the minus icon, the column should disappear, this worked with php, but the code is a mess and I would like to get this working with jQuery, i found some other threads that showed me this:</p>
  
  <pre><code>$("#minus").click(function() {
      $("#table td:nth-child(2),th:nth-child(2)").hide();
  });
  </code></pre>
  
  <p>After a while I came up with this:</p>
  
  <pre><code>var num = $("#columnid").index();    
  $("#table td:nth-child("+ num +"),th:nth-child("+ num +")").hide();
  </code></pre>
  
  <p>That kinda worked, but i need to call it with a <code>onclick="jquery_function();"</code> function and let php insert the id of every header, but is this possible? Or what is the other way of doing this? i'm stuck!</p>
  
  <p><strong>This did it:</strong></p>
  
  <pre><code>$(".minus").click(function() {
      var num = $(this).parent().index() + 1;
      $("#table td:nth-child("+ num +"),th:nth-child("+ num +")").fadeOut(250);
  });
  </code></pre>
  
  <p>Seems simple after figuring out, Jeroen had it right. :) The only thing i dont get is why you need the ("th"), works with and without. Thanks!</p>