jQuery not()メソッド

❮jQueryトラバースメソッド

クラス名「intro」を持たないすべての<p>要素を返します。

$("p").not(".intro")

定義と使用法

not()メソッドは、特定の基準に一致しない要素を返します。

このメソッドでは、基準を指定できます。基準に一致しない要素は選択から返され、一致する要素は削除されます。

このメソッドは、選択した要素のグループから1つ以上の要素を削除するためによく使用されます。

ヒント: not()メソッドは filter()メソッドの反対です。


構文

$(selector).not(criteria,function(index))

Parameter Description
criteria Optional. Specifies a selector expression, a jQuery object or one or more elements to be removed from a group of selected elements.

Tip: To specify multiple criteria, use comma.
function(index) Optional. Specifies a function to run for each element in a group. If it returns true, the element is removed. Otherwise, the element is kept.
  • index - The index position of the element in the set
Note: this is the current DOM element.

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


返す:evenセレクターをnot()と一緒に使用して、偶数ではないすべての<p>要素を返します。


クラス「intro」とID「outro」を持たないすべての<p>要素を返す方法。


、<div>要素内にクラス "intro"を持たないすべての<p>要素を返す方法。


要素を使用して、IDが「intro」でないすべての<p>要素を返す方法。


使用関数を使用して、内部に2つの<span>要素がないすべての<p>要素を選択する方法。


❮jQueryトラバースメソッド