Last active
February 24, 2016 16:56
-
-
Save cezarypiatek/fdec5fd1f12c3fe756bd to your computer and use it in GitHub Desktop.
Find duplicated id attributes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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