function who clicked

I have a function set up to run onclick of multiple items.
How can I figure out what was the id of the object that caused the function to run?
Who is Participating?
Chris StanyonConnect With a Mentor Commented:
This may be picky, but isn't ID an attribute:

id = $(this).attr('id');
GaryConnect With a Mentor Commented:
Both work but .prop() gives you the value after any changes (I know it's unlikely that you would be changing an id but...) whilst attr() will only give you the value as it existed at page load regardless of any changes to it.
So I prefer to use prop()
Chris StanyonCommented:
Gary - that's not true. prop() and attr() will give you the correct value, even if you change the ID. The ID is an attribute:

From W3c:

From jQuery Docs:

Summary of Preferred Usage

The .prop() method should be used for boolean attributes/properties and for properties which do not exist in html (such as window.location). All other attributes (ones you can see in the html) can and should continue to be manipulated with the .attr() method.
attr() will not always give you a dynamic value (tho you are right about the id et al)
Since 1.6.1 using attr() is basically defunct since all it does is call .prop() - so you may as well just use it to start with.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.