Access the clicked element
I have an element like this:
<p id='foo' onclick='go()'>hi</p>
function go() {
}
how do I get access to the element that generated the click (the p 开发者_Python百科element in this case)? Do I just do:
function go() {
var clicked = this;
}
Thanks
Like this:
<p id='foo' onclick='go(this)'>hi</p>
function go(elem) {
}
You could pass this
as an argument:
<p id='foo' onclick='go(this);'>hi</p>
function go(clicked) {
}
精彩评论