๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
JavaScript/Vanilla JS

[๋ฐ”๋‹๋ผJS๋กœ ํฌ๋กฌ ์•ฑ ๋งŒ๋“ค๊ธฐ] Events and event handlers

by ์ฝ”๋”ฉํ•˜๋Š” ๋ถ•์–ด 2021. 2. 26.
๋ฐ˜์‘ํ˜•

[์ถœ์ฒ˜-์œ ํŠœ๋ธŒ ๋…ธ๋งˆ๋“œ ์ฝ”๋” Nomad Coders]

https://youtu.be/LnuLDGO5848

-์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋Š” HTML๊ณผ CSS๋ฅผ ๋ฐ”๊พธ๋Š” ๊ธฐ๋Šฅ์„ ํ•˜์ง€๋งŒ ์ด๋ฒคํŠธ์— ๋ฐ˜์‘ํ•˜๊ธฐ ์œ„ํ•ด ๋งŒ๋“ค์–ด์กŒ๋‹ค

-์ด๋ฒคํŠธ๋ž€ ์›น์‚ฌ์ดํŠธ์—์„œ ๋ฐœ์ƒํ•˜๋Š” ๊ฒƒ๋“ค์„ ๋งํ•œ๋‹ค.

click,resize,submit,input, change, load, before, closing, printing ๋“ฑ๋“ฑ

-window๋Š” ์กฐ๊ธˆ ๋‹ค๋ฅธ ์ด๋ฒคํŠธ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค

-ํ•จ์ˆ˜ ๋’ค์— ()๋ฅผ ์“ฐ๋ฉด ์ง€๊ธˆ ๋ฐ”๋กœ ํ˜ธ์ถœํ•˜๋ผ๋Š” ๋œป

()๋ฅผ ์“ฐ์ง€์•Š์œผ๋ฉด ํ•จ์ˆ˜๋ฅผ ๋ฐ”๋กœ ์ฆ‰์‹œ ํ˜ธ์ถœํ•˜์ง€์•Š์Œ. ๋งค์šฐ๋งค์šฐ ์ค‘์š”!!

 

 

const title = document.querySelector("#title");

function handleResize() {
    console.log("I have been resized")
}

window.addEventListener("resize", handleResize);

 

 

const title = document.querySelector("#title");

function handleResize(event) {
    console.log(event);
}

window.addEventListener("resize", handleResize);

event๊ฐ€ ๋ฐœ์ƒํ•  ๋•Œ๋งˆ๋‹ค ์ด๋ฒคํŠธ ๊ฐ์ฒด๊ฐ€ ํ˜ธ์ถœ๋จ

 

 

const title = document.querySelector("#title");

function handleClick() {
    title.style.color = "red";
}

title.addEventListener("click", handleClick);

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€