How can I quickly get a jQuery selector for the textboxes in the the first 5 rows of a table? I have a table with many rows and many textboxes; I'm just trying to select the textboxes in the first 5 rows of the table. Is there an easy way to do this?
+8
A:
Use lt()
$('tr:lt(5) input[type=text]')
Note that it's lt(5), not lt(6), since the indexes are 0-based.
Patrick McElhaney
2009-08-04 17:09:49
if he has more than one table, this solution doesn't discern between them
Jason
2009-08-04 18:58:59
Yes this works fine. And yes jason you're correct. I would limit the scope of the selector by passing the appropriate table as the second arg to the query. thanks all. :)
Hcabnettek
2009-08-11 06:46:35
A:
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();
andres descalzo
2009-08-04 17:14:33