Last active
October 31, 2016 10:39
-
-
Save nhducit/3583240869bd49fe1e41091259e691bd to your computer and use it in GitHub Desktop.
Detect all duplicated element id in page
This file contains hidden or 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 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