티스토리 뷰
이벤트 핸들러 내부 this binding 시 currentTarget 속성과 target 속성의 차이
document.body.innerHTML = '<div id="clickDiv">클릭';
document.getElementById('clickDiv').addEventListener('click', function(event){
console.log(event.currentTarget);
console.log(event.target);
});
이벤트 핸들러가 바인딩된 엘리먼트는 event.currentTarget
이벤트가 실제로 발생한 엘리먼트는 event.target
참고
What is the exact difference between currentTarget property and target property in JavaScript
Can anyone please tell me the exact difference between currentTarget and target property in JavaScript events with example and which property is used in which scenario?
stackoverflow.com
DOC
https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget
Event.currentTarget - Web APIs | MDN
The currentTarget read-only property of the Event interface identifies the current target for the event, as the event traverses the DOM. It always refers to the element to which the event handler has been attached, as opposed to Event.target, which identif
developer.mozilla.org
https://developer.mozilla.org/en-US/docs/Web/API/Event/target
Event.target - Web APIs | MDN
The read-only target property of the Event interface is a reference to the object onto which the event was dispatched. It is different from Event.currentTarget when the event handler is called during the bubbling or capturing phase of the event.
developer.mozilla.org
- Total
- Today
- Yesterday
- Spring
- oracle
- window
- Kotlin
- LocalDate
- 베리 심플
- 북리뷰
- Spring Security
- intellij
- config-location
- jQuery
- svn
- docker
- rocky
- input
- mybatis config
- Java
- JavaScript
- localtime
- Bash tab
- maven
- Mac
- Linux
- LocalDateTime
- k8s
- mybatis
- elasticsearch
- claude
- 오라클
- springboot
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |