Skip to content

Instantly share code, notes, and snippets.

@cezarypiatek
Last active February 24, 2016 16:56
Show Gist options
  • Save cezarypiatek/fdec5fd1f12c3fe756bd to your computer and use it in GitHub Desktop.
Save cezarypiatek/fdec5fd1f12c3fe756bd to your computer and use it in GitHub Desktop.
Find duplicated id attributes
var ids = {};
var elementsWithId = document.querySelectorAll("[id]");
Array.prototype.forEach.call(elementsWithId, function(el){
var id = el.id;
if(ids[id]){
ids[id]++;
}else{
ids[id]=1;
}
});
Object.keys(ids).forEach(function(key){
if(key && ids[key]>1){
console.log(key+" : " + ids[key]);
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment