« Student class needs to be adjusted | Main | Textastic for iPad »

October 19, 2011

Alternately colour the rows in a table with jQuery

var color = '#efefef';

var counter = 0;

function switch_bg(counter){ 

    if(eval(counter/2) == eval(counter/2).toFixed(0)){ return color; } 

    else { return 'white'; } 

    }

jQuery('tbody tr').each(

	function(){ 
	
		counter++;  
		
		jQuery(this).find('td').each(
		
			function(){ 
			
				jQuery(this).css({ 'background-color' : switch_bg(counter) }); 
				
				}
			
			);
			
		}
			 
	);

Tags: jQuery

Posted by pj at October 19, 2011 06:42 PM