Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get row by index

Tags:

jquery

how can you get a row by the index?

var rows = $('tr', tbl);
rows.index(0).addClass('my_class');
like image 876
clarkk Avatar asked Jun 21 '11 16:06

clarkk


People also ask

How do you select rows based on index list?

Alternatively, you can select rows from the list index by using df. loc[df. index[]] method. loc[] method is used to select the rows by labels.

How do I select a specific row in a DataFrame by index in Python?

To select the rows, the syntax is df. loc[start:stop:step] ; where start is the name of the first-row label to take, stop is the name of the last row label to take, and step as the number of indices to advance after each extraction; for example, you can use it to select alternate rows.


2 Answers

Use .eq().

var rows = $('tr', tbl);
rows.eq(0).addClass('my_class');

...or for your simple case, .first():

rows.first().addClass('my_class');
like image 179
Matt Ball Avatar answered Oct 05 '22 21:10

Matt Ball


Using either the eq() function:

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


Or the :eq() selector:

$('tr:eq(0)', tbl).addClass('my_class');
like image 22
Town Avatar answered Oct 05 '22 21:10

Town