We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

noah on 05/28/08


Tagged

basic list easy ids


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

jserpa


List all IDs in the DOM tree


Published in: JavaScript 


List all the IDs on the page.

  1. var allTags = document.body.getElementsByTagName('*');
  2. var ids = [];
  3. for (var tg = 0; tg< allTags.length; tg++) {
  4. var tag = allTags[tg];
  5. if (tag.id) {
  6. ids.push(tag.id);
  7. }
  8. }
  9. alert(ids);

Report this snippet 

You need to login to post a comment.