Created
October 14, 2018 21:47
-
-
Save bradym/bff96dadf37de84f9a59f4252adb56a1 to your computer and use it in GitHub Desktop.
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
// Find duplicate ids | |
var allElements = document.getElementsByTagName("*"), allIds = {}, dupIDs = []; | |
for (var i = 0, n = allElements.length; i < n; ++i) { | |
var el = allElements[i]; | |
if (el.id) { | |
if (allIds[el.id] !== undefined) { | |
dupIDs.push(el.id); | |
} | |
allIds[el.id] = el.name || el.id; | |
} | |
} | |
if (dupIDs.length) { | |
console.error("Duplicate ID's:", dupIDs); | |
} else { | |
console.log("No Duplicates Detected"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From http://ryanguill.com/js/html/dom/2016/02/16/dom-find-duplicate-ids.html