Skip to content

Instantly share code, notes, and snippets.

@chainat
Created April 6, 2015 23:30
Show Gist options
  • Save chainat/825ac2a9da50989f3f55 to your computer and use it in GitHub Desktop.
Save chainat/825ac2a9da50989f3f55 to your computer and use it in GitHub Desktop.
Check duplicate html element ID on the page
(function findDuplicateIds(){
var ids = {};
var all = document.all || document.getElementsByTagName("*");
for(var i=0, l=all.length; i<l; i++){
var id = all[i].id;
if(id){
if(ids[id]){
console.log("Duplicate id: #" + id);
} else {
ids[id] = 1;
}
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment