tags:

views:

38

answers:

3

Dear experts

Is there a way to access the ID of an dom element?

I don't mean using the getElementById attribute to find out a array of objects.

Bascially 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.

+2  A: 

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.

Gaby
ty,sorry I forgot to mention,I am incorporating Jquery syntax into the equation.$(this).idIs there an jquery syntax for that
Dennis D
See Pointy's answer above. $(this).attr('id')
Kerry
@webzide, as @kerry mentioned, have a look at Pointy's answer for the jquery syntax.. ( *and also accept it as this is how thing are done around here ;)* )
Gaby
+1  A: 

In jQuery it's

 $(this).attr('id')

or

 $(this)[0].id
Pointy
A: 

It's works.

element.getAttribute('id');
zazk