JavaScript
#3.2 Searching For Elements
김예나
2023. 1. 24. 22:57
- app.js:3 Uncaught TypeError: Cannot set properties of null (setting 'innerText') at app.js:3:17 -> 코드 내의 어떤 값이 null이다
- classname 가져오기
const hellos = document.getElementsByClassName("hello");
console.log(hellos);
- tag name으로 가져오기
const title = document.getElementsByTagName("h1");
- css 찾기처럼 가져오기 -> hello 클래스 안에 있는 h1태그 가져오기, 여러개가 해당되도 첫번째 요소만 가져
const title = document.querySelector(".hello h1"); //하나의 요소만 가져옴
const title2 = document.querySelectorAll(".hello h1"); //모든 요소 가져옴,array형식으로
const title = document.querySelector("#hello");
const title2 = document.getElementById("hello"); //둘이 똑같음