Welcome to WebmasterWorld Guest from 107.21.175.43

Forum Moderators: open

Message Too Old, No Replies

Jquery highlight highest number

     

LinusIT

4:14 pm on Aug 3, 2011 (gmt 0)

5+ Year Member



I'm trying to highlight the highest number on each row or a table. I posted the question elsewhere and they provided the following code which works on jsFiddle.net but I can't get it working


<script type="text/javascript">
(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('highlight');
});
</script>


I can see that the code works, I imagine it's me missing something when putting the code into my page, hopefully someone can point out what I'm doing wrong.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month