It seems like it doesn't recognise the cells, because they are basically the first, second and third of their row.
After googling this, I ended up on this SO answer, but that didn't provide a solution for your problem either. Then, after a bit more specific search, I ended up on this SO answer, which basically says "you NEED a jQuery plugin". If you want, you can use those answers, but I'll provide an alternative that doesn't need any plugins.
To fix this, I would simply add a hidden (display:block
) cell below each colspan'd element. That way, JavaScript still recognises it as a space taken up. To make that work, I use the following jQuery function:
$('#demo-table td').each(function() {
if (!$(this).is('[rowspan]')) return;
var i = +$(this).attr('rowspan');
var $nextRow = $(this).parent('tr');
while (($nextRow = $nextRow.next()) && --i > 0) {
$nextRow.prepend('<td style="display:none;"></td>');
}
});
View demo.
I assumed here that your cells with a defined colspan
will always be at the start of the table row. If they are not, I'm going to have to add a bit of code to it, but it would be possible to do that too. Just leave a comment about it if you need it to work for other positions of colspan too.
To explain what this code does, it goes through each table cell, and checks if it has a rowspan attribute. If it doesn't, it continues with the next cell. If it does have a rowspan, then it first gets the row itself, and the rowspan assigned to the cell. It then goes through each next row, decrementing the given rowspan, until it's zero. For every row it goes through, it prepends a hidden cell. That cell will tell JavaScript that the other cells are in another column, so it will give the right coordinates.