Front-end/Vanilla JS
자바스크립트 document.querySelector
1924
2021. 12. 21. 03:21
document.querySelector는 css형태로 선언한다.
선언법
document.querySelector("tag"); // 일반 태그
document.querySelector("#id"); // 아이디
document.querySelector(".class"); // 클래스
보기와 같이 선언하면 되며,
배열형식은 document.querySelectorAll을 선언하면 된다.
document.querySelectorAll("h1, h2");
보기와 같이 입력하면 h1, h2가 모두 선택된다.