By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,521 Members | 1,259 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,521 IT Pros & Developers. It's quick & easy.

3 lines of code want to display all tags

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.