I have a link with this href:
href="javascript:foo(this);"
when I call it “this” points to the window object, not the link. How do I pass a reference to the link?
Edit note: The question is how to pass with href, not generally – I know about onclick!
And not copying id and make getElementById, that’s not “this”, it’s DOM search for certain element, no need to make it inline in HTML.
The anwer is: not possible.
When you use “javascript: …. ” in an href, you are calling this function globaly. Not in the context of the link.
You can try with:
http://jsfiddle.net/xMGKz/1/