CaffGeek CaffGeek - 6 months ago 54
jQuery Question

Removing columns, taking rowspan into account

I have the following example setup

What I am trying to do, is remove the first two columns of a table

The issue is that the first column, contains cells that have a


So when I remove it, then go to the next row, it removes a cell it shouldn't

Thoughts on how to make this work?


Since row spans are involved, you'll have to change your strategy. Your table has four columns, so instead of removing the first two columns, you should aim to keep only the last two.

You can achieve that easily by passing a negative upper bound to slice():

$(this).children("td, th").slice(0, -2).remove();

You will find an updated fiddle here.