I am trying to add a class to the last cell in each row of a table...this does not work...it only applies the rightStyle to the last element in the first (top) row...
//the last cell in every row all have border right
var lastIndex = getLastVisibleIndex();
var rows = $("table.scrollable tr");
rows.each(function () {
$("td:eq(" + lastIndex + ")").addClass(rightStyle)
});
Approach 2: Use $('table tr:last') jQuery Selector to find the last element of the table. The 'table' in query looks for the table element then 'tr' is looking for all the rows in the table element and ':last' is looking for the last table row of the table.
$(document). ready(function(){ var r=$("#testing":row2). val(); alert(r); });
Do it all in one line...
$('table tr td:last-child').addClass(rightStyle);
// Targeting a particular column as pointed out by FiveTools
// Note that :nth-child(n) is 1-indexed
$('table tr td:nth-child(3)').addClass('highlight');
http://jsfiddle.net/cobblers/hWqBU/
I used the nth-child...
$("table.scrollable td:nth-child(" + lastIndex + ")").addClass(rightStyle);
Some good alternative solutions here though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With