开发者

add css class to last column in each row in grid

开发者 https://www.devze.com 2023-01-15 17:41 出处:网络
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:

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

精彩评论

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