Hi, How do I access a tag's ID with the GetElmentBy method?
Shouldn't this: "document.getElementsByTagName('div').id;"
work?
| SitePoint Sponsor |

Hi, How do I access a tag's ID with the GetElmentBy method?
Shouldn't this: "document.getElementsByTagName('div').id;"
work?

<div id="example"></div>
document.getElementById('example');
John Conde | Facebook | Twitter
Brainyminds Merchant Account Services I Love Code eBook Giant
Authorize.Net: AIM API | ARB API | CIM API Get the FREE code!
Merchant Accounts 101 | Ecommerce 101
getElementsByTagName() always returns a NodeList, so you need to specify which node in the NodeList you want to deal with.
For example, you can do this:
Code:alert(document.getElementsByTagName('div')[0].id);
We miss you, Dan Schulz.
Learn CSS. | X/HTML Validator | CSS validator
Dynamic Site Solutions
Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

Hey Kravitz thanks a lot for your reply, I didn't realize that it would always return a Nodelist but I guess it would make sense! Very handy to know that!
Cheers
Bookmarks