title: Dynamically delete multiple columns in html table
body: <p>I am trying to delete multiple columns from html table using javascript.
  The logic it is using is that it searches in top row for tag "" and then deletes that column.</p>
  
  <p>The problem is if only one cell in top row is having '', then it deletes that columns fine,  but if there are multiple columns it throws error.</p>
  
  <p>Here is my code</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;body&gt;
  &lt;table style="width:100%" border='1' id='Just_for_california'&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;span&gt;&lt;/span&gt;&lt;/td&gt;
      &lt;td&gt;S&lt;/td&gt;      
      &lt;td&gt;&lt;span&gt;&lt;/span&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Eve&lt;/td&gt;
      &lt;td&gt;Jackson&lt;/td&gt;        
      &lt;td&gt;94&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;John&lt;/td&gt;
      &lt;td&gt;Doe&lt;/td&gt;        
      &lt;td&gt;80&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  
  &lt;/body&gt;
  
  
  &lt;script&gt;
  
  
  
      var dataTable_length = document.getElementById('Just_for_california').rows[0].cells.length;
      var count_rows = document.getElementById('Just_for_california').rows.length;
      var column_array = [];
      for(var i=0; i&lt;dataTable_length; i++)
      {
          var str = document.getElementById("Just_for_california").rows[0].cells[i].innerHTML;
          if(str.search("&lt;span&gt;&lt;/span&gt;") != -1)
          {
              column_array.push(i);
          }
  
      }
      var len = column_array.length;
      for(var i=count_rows-1 ; i&gt;=0;i--)
      {
          rows_number = document.getElementById('Just_for_california').rows[i];
          console.log("row_number:"+i);
  
              for(var j=0; j&lt;len;j++)
              {
                  rows_number.deleteCell(column_array[j]);
              }
  
      }
  
  
  
  
  &lt;/script&gt;
  &lt;/html&gt;
  </code></pre>