What is the difference between Target and currentTarget in the event context?
target
refers to the DOM element that triggers an event. Otherwise, currentTarget
refers to the DOM element that the event listener is listening on.
<ul class="todo-list">
<li class="item">Walk your dog</li>
</ul>
const list = document.querySelector(".todo-list");
list.addEventListener("click", e => {
console.log(e.target);
// Output: <li class="item">Walk your dog</li>
console.log(e.currentTarget);
// Output: <ul class="todo-list"></ul>
});
MEET THE NEW JSTIPS BOOK
You no longer need 10+ years of experience to get your dream job.
Use the 100 answers in this short book to boost your confidence and skills to ace the interviews at your favorite companies like Twitter, Google and Netflix.
GET THE BOOK NOW
MEET THE NEW JSTIPS BOOK
The book to ace the JavaScript Interview.
A short book with 100 answers designed to boost your knowledge and help you ace the technical interview within a few days.
GET THE BOOK NOW