JQuery: select the first five rows of a table

How to quickly get jQuery selector for text fields in the first 5 rows of a table? I have a table with many rows and many text fields; I'm just trying to select text fields in the first 5 rows of a table. Is there an easy way to do this?

+6
javascript jquery
source share
3 answers

Use lt ()

$('tr:lt(5) input[type=text]') 

Note that this is lt (5), not lt (6), since indexes are based on 0.

+11
source share

to try:

 $("#yourTable tr:lt(5) input[type=text]") 
+6
source share

see " http://docs.jquery.com/Selectors/nthChild#index "

try width:

 $("table tbody tr:nth-child(0)").html(); $("table tbody tr:nth-child(1)").html(); $("table tbody tr:nth-child(2)").html(); $("table tbody tr:nth-child(3)").html(); $("table tbody tr:nth-child(4)").html(); 
-one
source share

All Articles