jQuery eq() Metoda

❮ Metody przechodzenia jQuery

Przykład

Wybierz drugi element <p> (indeks 1):

$("p").eq(1).css("background-color", "yellow");

Definicja i użycie

Metoda eq() zwraca element o określonym numerze indeksu wybranych elementów.

Numery indeksów zaczynają się od 0, więc pierwszy element będzie miał numer indeksu 0 (nie 1).


Składnia

$(selector).eq(index)

Parameter Description
index Required. Specifies the index of the element. Can either be a positive or negative number.

Note: Using a negative number will start the index count from the end of the selected elements, instead of the beginning.

Spróbuj sam - przykłady


Użycie liczby ujemnej do zwrócenia drugiego elementu <p> od końca wybranych elementów.


❮ Metody przechodzenia jQuery