반응형
Notice
Recent Posts
Recent Comments
Link
taenyLog
Document : querySelector , querySelectorAll 본문
반응형
querySelector() : all-in-one method to select a single element
id, 클래스이름, 요소타입,속성 CSS 모두 사용 가능
일치하는 첫번째 요소만 반환한다.
# : 아이디 ex) #banner
. : 클래스 ex) .square
타입과 속성으로 선택한 예
> document.querySelector('a[title='Java']')
< <a href="/ " title="Java">Java</a>
<a>태그안의 title이 Java인 요소를 가져옴
querySelectorAll() : same idea, but returns a collecton of matching elements
일치하는 모든 요소 반환
> document.querySelectorAll('p a')
<p> 안에있는 <a> 모든 요소 반환한다.
반응형
'Web' 카테고리의 다른 글
Document : 속성 Attributes (0) | 2023.09.27 |
---|---|
Document : innerHTML, textContent, innerText (0) | 2023.09.27 |
Document: getElementById, getElementsByTagName, getElementsByClassName (0) | 2023.09.27 |
DOM(Document Object Model) (0) | 2023.09.27 |
[JavaScript] Destructuring 매개 변수 분해 (0) | 2023.09.26 |