Hcabnettek
Hcabnettek

Reputation: 12928

jQuery: select the first five rows of a table

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?

Upvotes: 8

Views: 6653

Answers (3)

Jason
Jason

Reputation: 52533

try:

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

Upvotes: 7

andres descalzo
andres descalzo

Reputation: 14967

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();

Upvotes: -1

Patrick McElhaney
Patrick McElhaney

Reputation: 59301

Use lt()

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

Note that it's lt(5), not lt(6), since the indexes are 0-based.

Upvotes: 14

Related Questions