jQuery eq()メソッド
例
2番目の<p>要素(インデックス番号1)を選択します。
$("p").eq(1).css("background-color", "yellow");
定義と使用法
eq()メソッドは、選択した要素の特定のインデックス番号を持つ要素を返します。
インデックス番号は0から始まるため、最初の要素のインデックス番号は0(1ではない)になります。
構文
$(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. |
自分で試してみてください-例
を使用する負の数を使用して、選択した要素の末尾から2番目の<p>要素を返します。