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'); });
Comments
Post a Comment