Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 379
Hcabnettek Avatar asked Aug 04 '09 17:08

Hcabnettek


People also ask

How do I get the first row of a table in jQuery?

You could also have table > thead > tr and then table > tbody > tr. So you might need to specify whether you want the first row from the thead or the tbody. find('tr:first') will select the tr in the thead.

How can get number of rows in table in jQuery?

Answer: Use the length Property You can simply use the length property to count or find the number of rows in an HTML table using jQuery. This property can be used to get the number of elements in any jQuery object.

How do you select the first element with the selector statement?

The :first selector selects the first element. Note: This selector can only select one single element. Use the :first-child selector to select more than one element (one for each parent). This is mostly used together with another selector to select the first element in a group (like in the example above).


1 Answers

Use lt()

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

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

like image 116
Patrick McElhaney Avatar answered Sep 20 '22 12:09

Patrick McElhaney