How to get the nth row in a table with a specific class

It is assumed below that the nth row is derived from a table with the .graphedRow class. It works for the first line, but not for others.

http://jsfiddle.net/hRpAw/

+3
source share
2 answers

Try instead .eq().

$('#someTable tbody .graphedRow').eq(pointIndex+1).css('background-color', '#FEFF9F');

Although it should be noted that eq()starts with 0 for the index.


There was a small check in Firebug.

:nth-childin this case a little faster than .eq(). (Hundreds of ms faster)

It also :nth-childworked fine, but it bases its index on all child elements #someTable tbody. It just returns those that have a class .graphedRow.

, JSFiddle, 6 <tr> <tbody>, .graphedRow ( 1-, 4- 6- <tr>). :nth-child(1), :nth-child(4), :nth-child(6), .

:nth-child - #someTable tbody (Other <tr>, )

- .eq() , .graphedRow #someTable tbody

+4

$('#someTable tbody > tr:nth-child('+index+')').css('background-color', '#FEFF9F')
+2

Source: https://habr.com/ru/post/1795419/


All Articles