user1768401 user1768401 - 1 month ago 13
jQuery Question

JQuery hide table columns with rowspan

I want to hide a table column, but using jQuery

.hide()
or
.toggle()
on columns with rowspan attribute seems to "pass" that attribute to the previous row and mess up the table.

$('#toggle').click(function(){
$('#tbl td:last-child').toggle();
});


Look at the simple example at:
http://jsfiddle.net/SEwVP/

Any ideas?

Answer

Thanks to the @dystroy for his input.

Based on his answer, here's the simple solution:

var lastChilds = $('#tbl td:last-child');
lastChilds.each(function(i){
    var rowSpan = $(this).attr('rowspan');
    if(rowSpan !== undefined){
      lastChilds.splice(i+1, rowSpan-1);
    }
    $(this).hide();
  });
Comments