Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Detect all duplicated element id in page
var nodes = document.querySelectorAll('[id]');
var ids = {};
var totalNodes = nodes.length;
for(var i=0; i<totalNodes; i++) {
var currentId = nodes[i].id ? nodes[i].id : "undefined";
if(!ids[currentId]) {
ids[currentId] = [];
}
ids[currentId].push(nodes[i]);
}
console.log('>>>Duplicated Ids:')
for (id in ids){if(ids[id].length > 1){console.log(ids[id])}}
console.log('>>>all ids:')
console.log(ids);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.