Reputation: 1343
Is there a way to access the ID of a DOM element?
I don't mean using the getElementById method to get an array of objects.
Basically I already know the DOM element and that object reference is at hand.
All I need is to access the ID property.
I know something like
if(element.id==value)
won't work.
Thanks in advance.
Upvotes: 2
Views: 1420
Reputation: 2985
I've verified that both element.id
and element.getAttribute('id')
work in Chrome/Safari/FF latest and IE 6-8.
Upvotes: 1
Reputation: 195972
Your code should work if the element
variable holds the dom element reference and it has an id defined..
Keep in mind that getElementById
will not return an array of object but a single object. You might be confusing it with getElementsByTagName
.
Upvotes: 3