CaffGeek CaffGeek - 1 year ago 89
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download