MDN self-hosted library · e01.org

Element: querySelectorAll() method

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

html
<section class="box" id="sect1">
  <div data-name="funnel-chart-percent1">10.900%</div>
  <div data-name="funnel-chart-percent2">3700.00%</div>
  <div data-name="funnel-chart-percent3">0.00%</div>
</section>
js
const refs = [
  ...document.querySelectorAll(`[data-name*="funnel-chart-percent"]`),
];
js
const matches = myBox.querySelectorAll("p");
js
const matches = myBox.querySelectorAll("div.note, div.alert");
js
const container = document.querySelector("#test");
const matches = container.querySelectorAll("div.highlighted > p");
js
const matches = document.querySelectorAll("iframe[data-src]");
js
const container = document.querySelector("#user-list");
const matches = container.querySelectorAll("li[data-active='1']");
js
const highlightedItems = userList.querySelectorAll(".highlighted");

highlightedItems.forEach((userItem) => {
  deleteUser(userItem);
});
html
<button id="select">Select</button>
<button id="select-scope">Select with :scope</button>

<div id="outer">
  #outer
  <div id="subject">
    #subject
    <div id="inner">#inner</div>
  </div>
</div>

<pre id="output"></pre>