Metoda jQuery eq() .
Příklad
Vyberte druhý prvek <p> (index číslo 1):
$("p").eq(1).css("background-color", "yellow");
Definice a použití
Metoda eq() vrací prvek se specifickým indexovým číslem vybraných prvků.
Indexová čísla začínají na 0, takže první prvek bude mít indexové číslo 0 (ne 1).
Syntax
$(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. |
Zkuste si to sami - příklady
Použití záporného čísla k vrácení druhého prvku <p> od konce vybraných prvků.