开发者

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) {
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜