Solved

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

Posted on 2014-03-12
2
263 Views
Last Modified: 2014-03-12
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
Comment
Question by:joyacv2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 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")

Open in new window

0
 
LVL 1

Author Closing Comment

by:joyacv2
ID: 39925054
works super fast!!!!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question