jQuery nextAll()メソッド

❮jQueryトラバースメソッド

クラス名が「start」の各<li>要素の次のすべての兄弟要素を返します。

$(document).ready(function(){
  $("li.start").nextAll().css({"color": "red", "border": "2px solid red"});
});

結果:

    ul (parent)
  • li (sibling)
  • li (sibling)
  • li (sibling with class name "start")
  • li (sibling)
  • li (sibling)
  • li (sibling)

定義と使用法

nextAll()メソッドは、選択した要素の次のすべての兄弟要素を返します。

兄弟要素は、同じ親を共有する要素です。

DOMツリー:このメソッドは、DOM要素の兄弟に沿って前方にトラバースします。

関連する方法:

  • next() -選択した要素の次の兄弟要素を返します
  • nextUntil() -2つの指定された引数の間のすべての次の兄弟要素を返します


構文

$(selector).nextAll(filter)

Parameter Description
filter Optional. Specifies a selector expression to narrow down the search for next siblings

Note: To return multiple siblings, separate each expression with a comma.

自分で試してみてください-例


を絞り込む次の兄弟要素の検索をフィルタリングする方法。


filterパラメーターを使用して、クラス名が「first」、「second」、および「third」を持つ<h2>要素のすべての兄弟を取得します。


のすべての次の兄弟要素を選択する方法。


を選択する各<div>要素のすべての次の兄弟<p>要素を選択する方法。


❮jQueryトラバースメソッド