Munawar Munawar - 1 year ago 67
jQuery Question

Jquery iterate table, having merged cells, rows and columns but skip first column

I am able to iterate all rows and columns but it does not work when table have merged cells.
It does not go through the merged row for all normal columns(not having any merged cells).

My script:

$('#test tr').each(function() {
$(this).find('td').each(function(colIndex)
{
if(colIndex > 1)
{
$(this).css('background-color', 'red');
}
});
});


A like example/test is available here:

Answer Source
$('#test tr').each(function() {



    var rowcount=0;
   $(this).find('td').each(function(colIndex)   
    {
        if(colIndex > 1)
        {
        $(this).css('background-color', 'red');
        }
      rowcount ++;
    }); 
  if(rowcount==2)
  {
     $(this).find('td').each(function(colIndex)   
    {
        if(colIndex == 1)
        {
        $(this).css('background-color', 'red');
        }

    });
  }


});

Modify your jquery like this. This will do. http://jsfiddle.net/dolours/pMWAw/26/