Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- CSS
- Link
- 일반 형제 선택자 결합
- map()
- 배열과 연결리스트의 차이
- 범용 선택자
- disabled
- classList.contains(string)
- 배열의 내림차순
- Em
- 가상 요소 선택자
- invalid assignment left-hand side
- 배열의 오름차순
- Array.from()
- for..of
- 등차수열의 항 찾기
- nth-child()
- display : none
- Sort
- 객체
- innerhtml
- 백준알고리즘
- 쌍방향 연결리스트
- filter()
- 단방향 연결리스트
- indexOf
- 인접 형제 선택자 결합
- 양방향 연결리스트
- 고차함수
- visibility : hidden
Archives
- Today
- Total
프론트엔드 센트럴파크 (☞゚ヮ゚)☞
querySelector() / querySelectorAll() 본문
querySelector() : 하나의 element를 return해준다.
이름이 같은 class가 여러개 있어도 무조건 첫번째의 element만 가져온다.
querySelectorAll() : 여러개의 element를 retrun해준다. (array 형태)
HTML
<div class = "title">
<h1>Hello</h1>
</div>
JS
const content = document.querySelector(".title h1");
JS
만약 id가 주어진다면 (div id = "title")
const content = document.querySelector("#title");
결론
const content = document.getElementById("title");
const content = document.querySelector("#title");
두개는 같은 것을 의미한다.
※ querySelector 를 더 많이 사용하는 이유
- css 형태로 가져올 수 있다 ("title h1:first-child");
- id와 class 둘 다 사용가능하다.
- class의 하위의 값도 가져올 수 있다.
'Javascript' 카테고리의 다른 글
innerText()과 innerHTML() 차이점 (0) | 2022.03.23 |
---|---|
innerHTML() (0) | 2022.03.22 |
getElementById() / getElementsByClassName() / getElementsByTagName() (0) | 2022.03.12 |
assigned a value but never used 오류 (0) | 2022.03.11 |
FileReader() (0) | 2022.01.11 |
Comments