event.target๊ณผ event.currentTarget์ ์ฐจ์ด๋ฅผ ์์์ผ ํจevent.target : ์ด๋ฒคํธ๊ฐ ๋ฐ์ํ ์์
event.currentTarget : ์ด๋ฒคํธ ํธ๋ค๋ฌ๊ฐ ๋ฑ๋ก๋์ด ์๋ ์์
ย
// ์นด๋ ํด๋ฆญ ์ ์นด๋ ์ด๋ฏธ์ง alert
const alertId = ({ target }) => {
if (target === cardSection) return null;
if (target.matches(".card")) alert(`์ํ id: ${target.id}`);
else alert(`์ํ id: ${target.parentNode.id}`);
};
// card click event handler
cardSection.addEventListener("click", alertId);
โก๏ธ ์นด๋ ํด๋ฆญ ์ ํด๋น ์นด๋์ ์ํ์ id๋ฅผ alertํ๋ ํจ์๋ฅผ ๋ง๋ค๊ธฐ ์ํด ์ด๋ฒคํธ ์์์ ์ฌ์ฉํ๋ค. ์ฌ๊ธฐ์ event.currentTarget์ cardSection์ด๋ค.
์ถ์ฒ : ์๋ฐ์คํฌ๋ฆฝํธ๋ฅ๋ค์ด๋ธ