var tds = $('td.value');
var arr = $.makeArray(tds);
arr.sort(function(a,b){
returnparseInt($(b).text()) - parseInt($(a).text());
});
$(arr[arr.length-2]).addClass('lowest');
$(arr[arr.length-1]).addClass('lowest');
css
td.lowest {background-color:lightgreen;}
Solution 2:
var ok = $('table tr td:last-child').map(function () {
return $(this).text();
}).get().sort(function (x, y) {
return x - y
});
alert(ok[0] + ' - is the smallest');
alert(ok[1] + ' - is the 2nd smallest');
values[0] and values[1] will be smallest and second smallest values respectively.
Solution 5:
This should do the trick:-
var values = $('td:last-child').sort(function(a, b) {
return $(a).text() - $(b).text();
}).slice(0, 2).css('color', 'red').map(function() {
return $(this).text();
}).get();
So, sort each td:last-child by its text() value (low to high), then use slice() to get the first two elements. Apply the css() to these elements, then use map() to return their text(), which will be assigned to var values
Post a Comment for "Get Two Lowest Values From A Table With Jquery"