Skip to content

Instantly share code, notes, and snippets.

@nhducit
Last active October 31, 2016 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nhducit/3583240869bd49fe1e41091259e691bd to your computer and use it in GitHub Desktop.
Save nhducit/3583240869bd49fe1e41091259e691bd to your computer and use it in GitHub Desktop.
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