Created
September 15, 2016 18:41
-
-
Save jwcarroll/c808e7a75cca2eafd6c76254940eb58c to your computer and use it in GitHub Desktop.
Simple recursive walk over DOM tree to create unique tags based on position
This file contains 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
// | |
// This can be used in Chrome console like: | |
// tagElementRecursive('',$0); | |
// | |
function tagElementRecursive(parentTag, node, index){ | |
const tag = [ | |
parentTag, | |
`${node.nodeName}_${index || 0}` | |
] | |
.filter(str => str) | |
.join('_'); | |
console.log(tag); | |
Array.prototype.forEach.call( | |
node.children, | |
tagElementRecursive.bind(this, tag) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment