jQuery off() 메서드

❮ jQuery 이벤트 메소드

예시

모든 <p> 요소에 대한 클릭 이벤트를 제거합니다.

$("button").click(function(){
  $("p").off("click");
});

정의 및 사용

off() 메서드는 on() 메서드에 연결된 이벤트 핸들러를 제거하는 데 가장 자주 사용됩니다 .

jQuery 버전 1.7부터 off() 메서드는 unbind(), die() 및 undelegate() 메서드를 대체합니다. 이 방법은 API에 많은 일관성을 제공하며 jQuery 코드 기반을 단순화하므로 이 방법을 사용하는 것이 좋습니다. 

참고: 특정 이벤트 핸들러를 제거하려면 이벤트 핸들러가 연결될 때 선택기 문자열이 on() 메서드에 전달된 문자열과 일치해야 합니다. 

팁: 한 번만 실행되고 자체적으로 제거되는 이벤트를 첨부하려면 one() 메서드를 사용하십시오.


통사론

$(selector).off(event,selector,function(eventObj),map)

Parameter Description
event Required. Specifies one or more events or namespaces to remove from the selected element(s).

Multiple event values are separated by a space. Must be a valid event
selector Optional. A selector which should match the one originally passed to the on() method when attaching event handlers
function(eventObj) Optional. Specifies the function to run when the event occurs
map Specifies an event map ({event:function, event:function, ...}) containing one or more event to attach to the elements, and functions to run when the events occur

직접 해보십시오 - 예


모든 클릭 이벤트 핸들러 제거 on() 메소드로 추가된 모든 <p> 요소에 대한 모든 클릭 이벤트 핸들러를 제거하는 방법.


제거 on() 메서드로 추가된 특정 함수를 제거하는 방법.


제거 이벤트가 특정 횟수만큼 트리거된 후 이벤트 핸들러를 제거하는 방법.


❮ jQuery 이벤트 메소드