querySelectorAll()
연결된 노트와 함께 읽기
문법
JavaScript
querySelectorAll("#id, .class");
예시
<div id="sections">
<ol class="section">
1
<li>1-1</li>
<li>1-2</li>
<li>1-3</li>
</ol>
<ol class="section">
2
<li>2-1</li>
<li>2-2</li>
<li>2-3</li>
</ol>
</div>
const sections = document.querySelectorAll("#sections , #sections .section");
// id가 sections인 태그와 class가 section인 경우를 모두 선택
console.log(sections.constructor.name); // NodeList를 반환
for(const i = 0; i < sections.length; i++) {
const item = sections.item(i);
item.style.border = "1px solid #ff0000";
}