var elements = document.getElementsByTagName("*"); for (i = 0; i < elements.length; i++) if (elements[i].id != "") for (j = 0; j < i; j++) if (elements[i].id == elements[j].id) { console.log("duplicate id: " + elements[j].id + "; idx " + i + " and " + j); break; }
and now formatted:
var elements = document.getElementsByTagName("*");
for (i = 0; i < elements.length; i++) {
if (elements[i].id != "") {
for (j = 0; j < i; j++) {
if (elements[i].id == elements[j].id) {
console.log("duplicate id: " + elements[j].id + "; idx " + i + " and " + j);
break;
}
}
}
}
It'll make a list of all the elements in a page, iterate over elements with ID and search for a duplicate entry reporting using console.log so you need to have a fairly modern browser to be using it (I mean ancient IE will not work)
Have fun!
No comments:
Post a Comment