472,127 Members | 1,469 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

3 lines of code want to display all tags

for(var i=0;i<document.all.elements.length;i++){
alert(document.forms[0].elements[i].id);
}

This code displays the ids of only controls in a form, but I'd like it to
display ALL items. For example, not just the ids of buttons, inputs, etc,
but any <span> elements as well. Is there something I could replace with
the "elements"? I tried tags but that doesn't work either.

Thanks!
Mike
Jul 20 '05 #1
3 4739
I figured it out. Here is the code:

for(var i=0;i<document.all.length;i++){
alert(document.all[i].id);
}
"Mike Hnatt" <do**@gladstone-inc.com> wrote in message
news:vo************@corp.supernews.com...
for(var i=0;i<document.all.elements.length;i++){
alert(document.forms[0].elements[i].id);
}

This code displays the ids of only controls in a form, but I'd like it to
display ALL items. For example, not just the ids of buttons, inputs, etc,
but any <span> elements as well. Is there something I could replace with
the "elements"? I tried tags but that doesn't work either.

Thanks!
Mike

Jul 20 '05 #2
Mike Hnatt wrote:
I figured it out. Here is the code:

for(var i=0;i<document.all.length;i++){
alert(document.all[i].id);
}


This is deprecated and does not work in every browser.
You should try a better way for this:

var all=document.getElementsByTagName("*");

for(var i=0; i<all.length; i++)
alert(all[i].id);

--
marcoos.org

Jul 20 '05 #3
Thanks Marek, I made the changes. I appreciate it,
Mike

"Marek A. Stepien" <ma******@spa.mu> wrote in message
news:bm**********@nemesis.news.tpi.pl...
Mike Hnatt wrote:
I figured it out. Here is the code:

for(var i=0;i<document.all.length;i++){
alert(document.all[i].id);
}


This is deprecated and does not work in every browser.
You should try a better way for this:

var all=document.getElementsByTagName("*");

for(var i=0; i<all.length; i++)
alert(all[i].id);

--
marcoos.org

Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Sims | last post: by
33 posts views Thread by Xah Lee | last post: by
7 posts views Thread by Yongsub Eric Shin | last post: by
9 posts views Thread by davetelling | last post: by
1 post views Thread by rn5a | last post: by
7 posts views Thread by =?Utf-8?B?TG9zdEluTUQ=?= | last post: by
1 post views Thread by CapRand | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.