Study/JavaScript
[JS] event.target
taecongs
2023. 7. 26. 15:42

알고있으면 좋은 Javascript Tip✨
event.target()
- 이벤트가 발생한 요소를 반환한다.
- event target(html 요소)에 지정된 event type(클릭이나 스크롤 등)이 발생하면 정의된 event handler(함수)가 실행된다.
$("a").click(function(event){
console.log(event.target);
});
- a 요소를 클릭 했을 때 이벤트가 발생한다.
- 이벤트가 발생할 때마다 이벤트 대상인 a 요소를 console.log로 출력한다.
- event.target과 this는 DOM 객체이므로, jQuery 객체가 아니기 때문에 jQuery 메서드를 사용할 수 없다.