Alex Rivera | Logout

get row by index

Asked 2011-06-21T16:20:55.757
14

how can you get a row by the index?

var rows = $('tr', tbl);
rows.index(0).addClass('my_class');
Edit
Report

2 Answers

9

Using either the eq() function:

rows.eq(0).addClass('my_class');


Or the :eq() selector:

$('tr:eq(0)', tbl).addClass('my_class');
answered 2011-06-21T16:22:41.213
3

You could use the native rows[docs] property on the HTMLTableElement.

$(tbl[0].rows[0]).addClass('my_class');

As noted by @Felix, I've assumed that tbl is a jQuery object. If not, do this:

$(tbl.rows[0]).addClass('my_class');
answered 2011-06-21T16:23:01.247

Your Answer