Find Verbose IDs in the DOM


 / Published in: JavaScript
 

Traverses the DOM tree and reports if any IDs are over 30 characters in length. Doesn't check for doubled IDs because that's caught when validationg the HTML.

  1. var allTags = document.body.getElementsByTagName('*');
  2. var ids = [];
  3. var longId = 0;
  4. for (var tg = 0; tg< allTags.length; tg++) {
  5. var tag = allTags[tg];
  6. if (tag.id) {
  7. ids.push(tag.id);
  8. if (tag.id.length > 30) longId++;
  9. }
  10. }
  11. alert(longId + " out of " + ids.length + " IDs are too long.")

Report this snippet  

You need to login to post a comment.