Skip to content

Instantly share code, notes, and snippets.

@SeanMcP
Last active June 26, 2024 12:47
Show Gist options
  • Save SeanMcP/ed0ad9685b0a7aa78b457f4301fb37de to your computer and use it in GitHub Desktop.
Save SeanMcP/ed0ad9685b0a7aa78b457f4301fb37de to your computer and use it in GitHub Desktop.
Find and print all headings on the given web page
document.querySelectorAll("h1,h2,h3,h4,h5,h6,[role=heading][aria-level]").forEach(node => {
let level = node.getAttribute("aria-level") || node.tagName[1];
let prefix = " ".repeat(parseInt(level) - 1);
console.log(`${prefix}${level}: ${node.textContent}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment