tags:

views:

51

answers:

3

What's the best way for selecting a table row by index using jQuery?

Thanks

+1  A: 

If you don't have to worry about nested tables:

$('#tableId tr').eq(4)
cobbal
No nested tables....thanks
Zach
A: 

Can't you just use tr[i]

twodayslate
I don't know...can you? If I knew I wouldn't have asked the question...
Zach
Well I wasn't exactly 100% sure so... just a thought.
twodayslate
if you want to do it without jQuery you can use `table.getElementsByTagName('tr')[i]`
cobbal
+1  A: 

You can do it all in the selector:

$('#tableId tr:eq(4)')
Pickle
This works (and is faster) if you know the index ahead of time. However I always avoid the string concatenation within the selector that would be necessary to allow dynamic selection.
cobbal