Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript">
jQuery(function($){
var colors = {}, td, color, p;
$('#t1').find('tr').each(function(){
if((td = $(this).find('td').get(0)) && (color = td.className)){
colors[color] = colors[color]? colors[color] + 1 : 1;
}
});
for (p in colors){
if(colors[p] > 1){
$('.' + p + ':gt(0)').remove();
$('.' + p).attr('rowspan', colors[p]);
}
}
});
</script>
</head>
<body>
<table border="1" cellpadding="10" cellspacing="0" summary="">
<thead>
<tr><th>Color</th><th>Item</th></tr>
</thead>
<tbody id="t1">
<tr><td class="Blue">Blue</td><td>Car</td></tr>
<tr><td class="Blue">Blue</td><td>Boat</td></tr>
<tr><td class="Blue">Blue</td><td>Motor</td></tr>
<tr><td class="Red">Red</td><td>Bus</td></tr>
<tr><td class="Yellow">Yellow</td><td>Scooter</td></tr>
<tr><td class="Yellow">Yellow</td><td>Bike</td></tr>
</tbody>
</table>
</body>
</html>
Or (using even more of jQuery):
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript">
jQuery(function($){
var colors = {}, td, color;
$('#t1').find('tr').each(function(){
if((td = $(this).find('td').get(0)) && (color = td.className)){
colors[color] = colors[color]? colors[color] + 1 : 1;
}
});
$.each(colors, function(color, num){
if(num > 1){
$('.' + color + ':gt(0)').remove();
$('.' + color).attr('rowspan', num);
}
});
});
</script>
</head>
<body>
<table border="1" cellpadding="10" cellspacing="0" summary="">
<thead>
<tr><th>Color</th><th>Item</th></tr>
</thead>
<tbody id="t1">
<tr><td class="Blue">Blue</td><td>Car</td></tr>
<tr><td class="Blue">Blue</td><td>Boat</td></tr>
<tr><td class="Blue">Blue</td><td>Motor</td></tr>
<tr><td class="Red">Red</td><td>Bus</td></tr>
<tr><td class="Yellow">Yellow</td><td>Scooter</td></tr>
<tr><td class="Yellow">Yellow</td><td>Bike</td></tr>
</tbody>
</table>
</body>
</html>
Bookmarks