title: Jquery Toggle Table Column Using a Better Method
body: <p>I have a table with around 30 columns and the idea is to let the user select which columns to be hidden or shown. The reason for this is to let them select which columns will be visible when they print.</p>
  
  <p>To tackle this problem, I have assigned a class name to each column and i'm using jQuery's toggle function. This works fine, but I was wondering if there is a better way to go about it that is more efficient and cleaner than what I am currently using. I have a separate function for each column and my code looks like this:</p>
  
  <p><strong>jQuery</strong></p>
  
  <pre><code>function tablecolumn1toggle(){
      $(".column1").toggle();
  }
  
  function tablecolumn2toggle(){
      $(".column2").toggle();
  }
  
  function tablecolumn3toggle(){
      $(".column3").toggle();
  }
  </code></pre>
  
  <p><strong>HTML</strong> Simplified
          toggle column 1
          toggle column 2
          toggle column 3</p>
  
  <pre><code>    &lt;table class="table table-bordered" id="points_table"&gt;
       &lt;tbody&gt;
       &lt;tr&gt;
          &lt;th class="column1&gt;Route&lt;/th&gt;
          &lt;th class="column2"&gt;Location&lt;/th&gt;
          &lt;th class="column3&gt;Track&lt;/th&gt;
       &lt;/tr&gt;
       &lt;/tbody&gt;
       &lt;/table&gt;
  </code></pre>
  
  <p>and so on..</p>
  
  <p>I am using a button to call each toggle function, I will use checkboxes once I have the basic code working. So, is there a way for me to cut down the amount of code?</p>
  
  <p><strong>EDIT: Thank you all for your answers, it was really hard to pick a single answer but i'm grateful for all your input.</strong></p>