开发者

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');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜