riverlee1132의 공책
[바닐라JS] HTML의 요소를 JS로 가져오기 본문
HTML
<body>
<div id="box1">
<Input type="text" placeholder="your message"></Input>
<button>확인</button>
</div>
</body>
HTML에 있는 input과 button을 JS로 가져오는 방법
바닐라JS 방법1
const getEle = document.getElementById("box1");
const getInput = getEle.querySelector("input");
const getBtn = getEle.querySelector("button");
바닐라JS 방법2
const getInput = document.querySelector("#box1 input");
const getBtn = document.querySelector("#box1 button");
'오답노트' 카테고리의 다른 글
| [머티리얼] large screens (0) | 2022.12.06 |
|---|---|
| [바닐라JS] JS와 HTML (0) | 2022.11.18 |
| [바닐라JS] 기초 용어들 (0) | 2022.11.10 |