jQuery not() 메서드

❮ jQuery 탐색 방법

예시

클래스 이름 "intro" 가 없는 모든 <p> 요소를 반환합니다 .

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

정의 및 사용

not() 메서드는 특정 기준과 일치하지 않는 요소를 반환합니다.

이 방법을 사용하면 기준을 지정할 수 있습니다. 기준과 일치하지 않는 요소는 선택 항목에서 반환되고 일치하는 요소는 제거됩니다.

이 방법은 선택한 요소 그룹에서 하나 이상의 요소를 제거하는 데 자주 사용됩니다.

팁: 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.

직접 해보십시오 - 예


모든 <p> 요소를 반환합니다. not()과 함께 :even 선택자를 사용하여 짝수가 아닌 모든 <p> 요소를 반환합니다.


클래스 "intro" 및 ID "outro"가 없는 모든 <p> 요소를 반환하는 방법.


<div> 요소 내부에 "intro" 클래스가 없는 모든 <p> 요소를 jQuery 객체와 함께 반환하는 방법.


ID "intro"가 없는 모든 <p> 요소를 DOM 요소와 함께 반환하는 방법.


사용 함수를 사용하여 내부에 두 개의 <span> 요소가 없는 모든 <p> 요소를 선택하는 방법.


❮ jQuery 탐색 방법