inline javascript: can it retrieve reference to the element it was invoked from?
On basically any element you can put a onclick='func()'
or some such to run JS when interacted with. Is there any way to get a reference to the DOM element itself?
When i do the obvious thing: <input type='button' onclick='开发者_JAVA百科alert(self);' />
I get [Object DOMWindow]
, which isn't quite as convenient as I'd hoped.
I realize I can easily hack my way through it by using id's or classes. But that means for each new custom-code button i create I must ensure it has a unique self referencing id, which I'd like to do without because that is more difficult to maintain.
Inline event handlers embedded in the HTML are called with this
being the element in question.
<input type='button' onclick='alert(this);' />
精彩评论