开发者

jquery row selection from index

I want, given a table id and a row index (0-based), to select the row at that index so that I c开发者_运维知识库an apply a background color to all of its td's. I'm familiar with basic selection, but am not sure how to do this using an index variable.


This should do the trick for you:

$('#id tbody > tr').eq(rowindex)

or, per your request in comments:

$('#id tbody > tr').eq(rowindex).children().addClass('myClass');


var selectedRow = 4 $('#myID tr:eq(' + selectedRow + ')');

would give you the 5th row.


$(#tableID)[0].rows[rowNumber]


Correct me if I'm wrong but I don't see any reasons from your example why you would addClass to each cell of a row. Unless, off course, you want to select a custom set of row cells. If not, you can simply apply a class, for ex "selected", to your selected row and write css like this:

tr td {
    background-color: #fff;
}
tr.selected td {
    background-color: #fffccc;
}

Or you can even try to set a background-color of a whole row.

Good luck!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜