Better way to loop through table columns?

I'm using two .each() loops through table columns -- first column loop then second column loop -- to set column styles based on column values, as follows:
<script type="text/javascript">
$(document).ready(function(){
    $('tbody tr td:nth-child(1)').each(function() {
        if ($(this).text()>'480') {
            $(this).addClass('red');
            }
    });
    $('tbody tr td:nth-child(2)').each(function() {
        if ($(this).text()=='Boy') {
            $(this).addClass('blu');
            }
    });
});
</script>

Open in new window

Although this works successfully, it seems to be inefficient as it loops the same table rows twice.

What I would like to do is to loop the rows once only, and then in each .each() iteration I would like to test both column1 and then column2 to set their Class, but I cannot work out how to do that (something like):

<script type="text/javascript">
$(document).ready(function(){
    $('tbody tr').each(function() {
        // test first td column
 
        // test second td column
     
    });
});
</script>

Open in new window

Can anyone point me in the right direction?
ShanghaiDAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
try:
$('tbody tr td').each(function(i) {
	if( !(i % 2) )
	{
	        if (1*$(this).text()>480) {
    	        	$(this).addClass('red');
        	}
	}
	else
	{
	        if ($(this).text()=='Boy') {
    	    	    $(this).addClass('blu');
        	}
	}
    });

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ShanghaiDAuthor Commented:
Thank you!  I will post a foliow up query to expand on this solution.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.