greeting.js note - 8hal/momonton_study GitHub Wiki

[question greeting_js_01] what is event.target?

Event.target

  • A reference to the object that dispatched the event.
  • It is different from event.currentTarget when the event handler is called during the bubbling or capturing phase of the event.


More things

์ด๋ฒคํŠธ ๋ฒ„๋ธ”๋ง, ์ด๋ฒคํŠธ ์บก์ฒ˜ ๊ทธ๋ฆฌ๊ณ  ์ด๋ฒคํŠธ ์œ„์ž„๊นŒ์ง€

  • ์ด๋ฒคํŠธ ๋ฒ„๋ธ”๋ง์€ ํŠน์ • ํ™”๋ฉด ์š”์†Œ์—์„œ ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ–ˆ์„ ๋•Œ ํ•ด๋‹น ์ด๋ฒคํŠธ๊ฐ€ ๋” ์ƒ์œ„์˜ ํ™”๋ฉด ์š”์†Œ๋“ค๋กœ ์ „๋‹ฌ๋˜์–ด ๊ฐ€๋Š” ํŠน์„ฑ์„ ์˜๋ฏธํ•œ๋‹ค.
  • ์ด๋ฒคํŠธ ์บก์ณ๋Š” ์ด๋ฒคํŠธ ๋ฒ„๋ธ”๋ง๊ณผ ๋ฐ˜๋Œ€ ๋ฐฉํ–ฅ์œผ๋กœ ์ง„ํ–‰๋˜๋Š” ์ด๋ฒคํŠธ ์ „ํŒŒ ๋ฐฉ์‹์ด๋‹ค.
  • ์ด๋ฒคํŠธ ์œ„์ž„์€ โ€˜ํ•˜์œ„ ์š”์†Œ์— ๊ฐ๊ฐ ์ด๋ฒคํŠธ๋ฅผ ๋ถ™์ด์ง€ ์•Š๊ณ  ์ƒ์œ„ ์š”์†Œ์—์„œ ํ•˜์œ„ ์š”์†Œ์˜ ์ด๋ฒคํŠธ๋“ค์„ ์ œ์–ดํ•˜๋Š” ๋ฐฉ์‹โ€™์ด๋‹ค.
// var inputs = document.querySelectorAll('input');
// inputs.forEach(function(input) {
// 	input.addEventListener('click', function() {
// 		alert('clicked');
// 	});
// });
// ํ•˜์œ„ ์š”์†Œ์— addEventListener ๋‹ฌ๊ธฐ
var itemList = document.querySelector('.itemList');
itemList.addEventListener('click', function(event) {
	alert('clicked');
});

// ์ƒˆ ๋ฆฌ์ŠคํŠธ ์•„์ดํ…œ์„ ์ถ”๊ฐ€ํ•˜๋Š” ์ฝ”๋“œ
// ...