Skip to content

Instantly share code, notes, and snippets.

@ryanguill
Last active August 29, 2015 14:02
Show Gist options
  • Save ryanguill/36af48201e6d68dbbbe3 to your computer and use it in GitHub Desktop.
Save ryanguill/36af48201e6d68dbbbe3 to your computer and use it in GitHub Desktop.
Small script that you can run in the console to see if you have more than one element with the same ID.
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