Skip to content

Instantly share code, notes, and snippets.

@bradym
Created October 14, 2018 21:47
Show Gist options
  • Save bradym/bff96dadf37de84f9a59f4252adb56a1 to your computer and use it in GitHub Desktop.
Save bradym/bff96dadf37de84f9a59f4252adb56a1 to your computer and use it in GitHub Desktop.
// 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");
}
@bradym
Copy link
Author

bradym commented Oct 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment