Link to home
Start Free TrialLog in
Avatar of rivkamak
rivkamakFlag for United States of America

asked on

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?
SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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()
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:

http://www.w3.org/TR/SVGTiny12/attributeTable.html

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.