add css class to last column in each row in grid
I have a grid which has x rows and 6 columns. I want to add a class to the 开发者_如何学Clast column in each row.
To get the 5th cell, if it's the last, use :last-child
, like this:
$(function() {
$("#myTable td:last-child").addClass("myClass");
});
To get the 5th no matter what, use the :nth-child()
selector, like this:
$(function() {
$("#myTable td:nth-child(5)").addClass("myClass");
});
refer : :last , $.eq() for information
$('td:last').addClass('addedClass');
or
var td = $('td');
td.eq(td.length - 1).addClass('addedClass');
精彩评论