728x90

$('.class or #id').click(function(e){
     e.target;                   //지금 실제로 클릭한 요소
     e.currentTatget;          //지금 이벤트리스너가 달린곳
     $(this);                     //지금 이벤트리스너가 달린곳
     e.preventDefault;        //기본동작막기
     e.stopPropagation();    //선택한 곳의 상위요소로의 이벤트 버블링을 중단할때 사용
});

$('.black-background').click(function(){     
     if ( e.target == e.currentTarget ){
          $(
'.black-background').hide() }
});

위에서 처럼 if문 쓸때 e.target == $("#id") 이렇게 조건을 주면 안먹힌다.

e.target는 쌩 자바스크립트고 $("#id")는 제이쿼리기 때문에 서로 인식을 못한다.

서로 비교할려면 자바스크립트끼리 하거나 제이쿼리 끼리 해야한다.

 

https://tutorialpost.apptilus.com/code/posts/jquery/jq-event-handling/

 

jQuery 이벤트 핸들링

jQuery Event 처리 on() 메서드를 통해 모든 이벤트를 처리할 수 있다. 같은 이벤트 핸들러 메서드는 사용을 자제해야 한다.

tutorialpost.apptilus.com

 

http://daplus.net/javascript-javascript-jquery%EC%97%90%EC%84%9C-e%EB%8A%94-%EB%AC%B4%EC%97%87%EC%9D%84-%EC%9D%98%EB%AF%B8%ED%95%A9%EB%8B%88%EA%B9%8C/

728x90

'jQuery' 카테고리의 다른 글

HTML에 데이터 저장하기 (커스텀 데이터, 제이쿼리)  (0) 2022.03.02
[jQuery] each  (0) 2021.12.08

+ Recent posts