Last active
June 26, 2024 12:47
-
-
Save SeanMcP/ed0ad9685b0a7aa78b457f4301fb37de to your computer and use it in GitHub Desktop.
Find and print all headings on the given web page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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