Created
June 22, 2025 12:57
-
-
Save jrc03c/b6e5f4bb3caf1e8625f899d9035db1e3 to your computer and use it in GitHub Desktop.
Get all elements in a 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
function getAllElements(root) { | |
root = root || document.body | |
const out = [root] | |
if (root.children) { | |
Array.from(root.children).forEach(child => { | |
out.push(...getAllElements(child)) | |
}) | |
} | |
return out | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment