javascript - If <td> has the largest int, in its <tr> add css class to <td> - jquery -


ive got table of data, , i'm trying @ glance on , find highest number on each row.

to i'm adding css class called highest highest <td>

  <tr>       <td>4.2</td>       <td class="highest">5.0</td>       <td>2.9</td>   </tr> 

with css

td.highest {font-weight:bold;} 

but hardcoded, i'm trying work out how write using jquery, i'm pretty new js , not sure start, looking @ using math.max can tell thats used on arrays, rather reading html, ideas ?

i've made jsfiddle here - http://jsfiddle.net/pudle/veuuq/

first bash - shorter (and potentially more efficient) answers may available...

$('tr').each(function() {     var $td = $(this).children();      // find values     var vals = $td.map(function() {         return +$(this).text();     }).get();      // find maximum     var max = math.max.apply(math, vals);      // tag cell matching max value     $td.filter(function() {         return +$(this).text() === max;     }).addclass('highest'); }); 

demo @ http://jsfiddle.net/alnitak/dggun/


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -