forked from loverajoel/jstips
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
585166f
commit 13748ed
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
_posts/en/javascript/2020-10-22-difference-between-target-and-currentTarget.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
layout: post | ||
|
||
title: What is the difference between Target and currentTarget in the event context? | ||
tip-number: 77 | ||
tip-username: loverajoel | ||
tip-username-profile: https://www.twitter.com/loverajoel | ||
tip-tldr: Temporal Dead Zone is a JavaScript behavior while using variables declared using `let` and `const` keywords. | ||
|
||
categories: | ||
- en | ||
- javascript | ||
--- | ||
`target` refers to the DOM element that triggers an event. Otherwise, `currentTarget` refers to the DOM element that the event listener is listening on. | ||
|
||
```html | ||
<ul class="todo-list"> | ||
<li class="item">Walk your dog</li> | ||
</ul> | ||
``` | ||
|
||
```js | ||
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> | ||
}); | ||
``` |