Select only nth-child of a specific item type

I have several forms, and I would like to select only the first and second input fields for each form

$("form input:nth-child(1), form input:nth-child(2)");

But this does not work, because each input has a label next to it, so there is no input nth-child(1).

Jsbin example

+3
source share
2 answers

You can do this using :lt(), for example:

$("form input:lt(2)");

This selects all elements that match less than the passed index, the first and second elements are index 0 and 1 and will match this selector :)

+4
source

You can use eq():

$("form input:eq(0), form input:eq(1)");

.

+3

Source: https://habr.com/ru/post/1751732/


All Articles