Reputation: 2587
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:
Upvotes: 1
Views: 867
Reputation: 976
$('#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/
Upvotes: 1
Reputation: 1123
Can be simplified to one line - just use the :last-child
selector
$('#test tr td:last-child').css('background-color', 'red');
Upvotes: 1