Table of Contents

show_ids

Posted 2002-10-02 @ 21:44:27

Somebody on WD requested a favelet to generate a list of the values of all IDs used in the current document. I'm not exactly sure when or why, but it seems like this could be a useful thing. So, here it is:

Show IDs

I've only tested on IE5:Mac, but it should also work for IE4 or later on Windows.

For those interested in the nuts & bolts, here's what your browser parses when you select that link:


javascript:e='';for(i=0;i%3Cdocument.all.length;i++)if(document.all
%5Bi%5D.id)e+=document.all%5Bi%5D.id+'%3Cbr%3E';if(e!='')document.write
('%3Cdiv%20align=%22center%22%3E'+e+'%3C/div%3E');else%20alert('No%20
elements%20with%20ID.')

I know it seems like somewhat of a cryptic mess, but there's really nothing fancy happening here. For reference, here's the same script, before I faveletized it:


e='';
for(i=0;i < document.all.length;i++)
    if(document.all[i].id)
              e+=document.all[i].id+'<br>';
if(e!='')
        document.write('<div align="center">'+e+'</div>');
else
  alert('No elements with ID.')

I threw together an AppleScript this morning that makes quick work of such conversions, so I'll try to remember to clean it up & post it sometime in the next week or so.