tags:

views:

33

answers:

2

In code I have a reference to a DOM element, in Jquery. How do I find out it's id? It maybe counter-intuitive, but I need to know that so I can do some manipulations on another element with a similar name.

+2  A: 
$(this).attr("id")
harpax
thanks, I so wished i had asked thid question 12 hours ago, when I was about to give my presentation and the prototype was busted because I couldn't find the id of my element. sucks, but this will save me at some other demo :)
halivingston
+1  A: 

If you want the id then you can use

$("youelementselector").attr("id");

and if you want elements name then

$("youelementselector").attr("name");

See attr

rahul