Jesusaddict avatar

jQuery Click 이벤트 중복 오류

jesusaddict

Published: 08 Jan 2018 › Updated: 08 Jan 2018jQuery Click 이벤트 중복 오류

jQuery Click 이벤트 중복 오류

jQuery를 이용해서 click 이벤트를 걸어주는 코딩을 자주 사용한다.

$("#id").on('click', function() {
    
}



그런데 이렇게 사용하면, 이벤트가 중복으로 걸리는 경우가 있다.
페이지가 refresh되지 않고, 한 페이지에서 여러번 스크립트가 실행하면 두배씩 이벤트가 발생한다.
그래서 아래와 같이 코드를 사용하면 이벤트 중복을 방지 할 수 있다.

$("#id").off().on('click', function() {
    
}



이렇게 하면 id에 해당하는 이벤트가 모두 사라진다.
Click이벤트만 제거 하고 싶다면 아래와 같이 코드를 바꾸면 된다.

$("#id").off("click").on('click', function() {
    
}

-fin.

Leave jQuery Click 이벤트 중복 오류 to:

Written by

신규 ICO 소개 / 일상사진 / 맛스팀 / 육아 / 운동과다이어트

Read more #jquery posts


Best Posts From Jesusaddict

We have not curated any of jesusaddict's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From Jesusaddict