HIT해

JavaScript 본문

Vue/JavaScript 알고리즘

JavaScript

힛해 2023. 5. 16. 20:56
728x90

const title = document.querySelector(" .hello h1")

// .hello class  를 가진 h1의 documents를 title 에 저장해라 라는 의미입니다.

 

그런데 만약

< h1 class id = "hello"> grab 1 <h1>

< h1 class id = "hello"> grab 2 <h1>

< h1 class id = "hello"> grab 3 <h1>

일때

const title = document.querySelector(" .hello h1")

console.log(title); 을 하면

grab1 

즉 첫번째 것만 출력된다

 

만약 세가지 전부 가져오고 싶다면

const title = document.querySelectorALL(" .hello h1")

 

만약

document.getElementById("hello"); 처럼 id를 통해 가져오고 싶다면

documet.querySelector("#hello"); 로 가져올 수 있다.

'Vue > JavaScript 알고리즘' 카테고리의 다른 글

[JS 백준] 1929.소수 구하기  (0) 2024.01.06
[JS 백준] 1978.소수찾기  (0) 2024.01.05
[JS 백준] 10798.세로읽기  (0) 2024.01.05
[JS 백준] 2443 단어 길이 재기  (0) 2024.01.04
[JS 백준] 2563.색종이  (0) 2024.01.04