Skip to content

Instantly share code, notes, and snippets.

@jwcarroll
Created September 15, 2016 18:41
Show Gist options
  • Save jwcarroll/c808e7a75cca2eafd6c76254940eb58c to your computer and use it in GitHub Desktop.
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 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