| Highlight highest number in a table Have working code already, just needs tweaking |
LinusIT

msg:4372676 | 11:41 am on Oct 10, 2011 (gmt 0) | I had a table with 3 columns, Item Name, Price 1, Price 2 and I wanted to highlight the highest price, I got this working with a little helping hand. I now need to change it so on one table row I have 3 items, so the layout would be: Item 1, Price1, Price2 - Item 2, Price1, Price 2 - Item3, Price1, Price2. What I'm trying to achieve is highlight the highest the highest price for each item. I've fiddled with the code I already have but cannot get it working, I'm hoping someone can point me in the right direction. Here's what I have at the moment: <script type='text/javascript'> //<![CDATA[ $(window).load(function(){ (function($) { $.fn.max = function(callback) { var max = null, maxIndex = null; this.each(function() { var value = callback.call(this); if (+value === value) { if (!max || value > max) { max = value; maxIndex = $(this).index(); } } }); return max !== null ? this.eq(maxIndex) : $(); }; }(jQuery)); $('tr').each(function() { $(this).children('td').max(function() { var value = +$(this).text().substr(1); if (!isNaN(value)) { return value; } }).addClass('green bold'); }); }); //]]> </script> |
|
|
|