x
Solved

# how to find maximum in a html table and apply a class

Posted on 2014-03-12
Medium Priority
270 Views
Hi,

I found the following code, but runs extremely slow in my program, how i can find a maximum in each column of a table and apply a class?

Note: This is a example of what i need, but runs extremely slow. Other codes that i found, only apply the class to the last maximum in the column, for example, if i have a column that have    10,123,120,123,115 only selects the last 123 and not both
http://jsfiddle.net/sbonkosky/Gfexm/
0
Question by:joyacv2

LVL 58

Accepted Solution

Gary earned 2000 total points
ID: 39924948
Don't know if this going to work any faster

http://jsfiddle.net/GaryC123/Gfexm/9/
``````var max1 = 0;
var max2 = 0;
var max3 = 0;
\$('table tr').each(function()
{
\$this = parseFloat( \$("td:first-child",this).text() );
if (\$this > max1) max1=\$this
\$this = parseFloat( \$("td:nth-child(2)",this).text() );
if (\$this > max2) max2=\$this
\$this = parseFloat( \$("td:nth-child(3)",this).text() );
if (\$this > max3) max3=\$this
});
\$('table tr td:first-child').filter(function() {return \$(this).html() == max1;}).addClass("max")

\$('table tr td:nth-child(2)').filter(function() {return \$(this).html() == max2+"%";}).addClass("max")

\$('table tr td:nth-child(3)').filter(function() {return \$(this).html() == max3+"kg";}).addClass("max")
``````
0

LVL 1

Author Closing Comment

ID: 39925054
works super fast!!!!
0

## Featured Post

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.