Vanilla JS๋ฅผ ๋ฅ์ํ๊ฒ ๋ค๋ฃจ๊ธฐ ์ํด์๋ DOM์ ์กฐ์ํ๋ ๋ฐฉ๋ฒ์ ์์์ผ ํ๋ค.
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Entendendo o DOM (Document Object Model)</title>
</head>
<body>
<div class="container">
<h1><time>00:00:00</time></h1>
<button id="start">Start</button>
<button id="stop">Stop</button>
<button id="reset">Reset</button>
</div>
</body>
</html>
const myStart = document.getElementById('start');
์ด ๋ฉ์๋๋ ์ ๋ฌ๋ ์ด๋ฆ id๊ฐ ํฌํจ๋ ์๋ฆฌ๋จผํธ๋ฅผ ๋ฐํ. id๋ ๊ณ ์ ํด์ผํ๊ธฐ ๋๋ฌธ์ ์ํ๋ ์์๋ฅผ ๊ฐ์ ธ์ค๋ ๋ฐ ๋งค์ฐ ์ ์ฉ.
const myContainer = document.getElementByClassName('container');
์ด ๋ฉ์๋๋ ์ ๋ฌ๋ ํน์ ์ด๋ฆ ํด๋์ค๋ฅผ ํฌํจํ๋ ๋ชจ๋ ์์์ HTMLCollection์ ๋ฐํ.
const resetButton = document.querySelector('#reset');
๊ดํธ ์์ ์ ๊ณตํ ์ ํ์์ ์ผ์นํ๋ ๋ฌธ์ ๋ด ์ฒซ๋ฒ์งธ element๋ฅผ ๋ฐํ.
const myButtons = document.querySelector('#buttons');
๊ดํธ ์์ ์ ๊ณตํ ์ ํ์์ ์ผ์นํ๋ ๋ฌธ์ ๋ด ๋ชจ๋ element๋ฅผ ๋ฐํ.
์๋ฐ์คํฌ๋ฆฝํธ์ ๊ธฐ์ด (๋ฐ์ดํฐ ํ์ ๊ณผ ํจ์) (0) | 2024.06.11 |
---|---|
๋ฐฐ์ด ๋ฉ์๋ ๋ณํ (0) | 2024.03.24 |
๋ฐฐ์ด ๋ฉ์๋ ์ํ์ ํ์ (0) | 2024.03.24 |
๋ฐฐ์ด ๋ฉ์๋ ์์ ์กฐ์ (0) | 2024.03.24 |
async/await (0) | 2024.02.20 |