tags:

views:

20

answers:

2

Hi,

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 element in this case)? Do I just do:

function go() {
    var clicked = this;
}

Thanks

+2  A: 

Like this:

<p id='foo' onclick='go(this)'>hi</p>

function go(elem) {
}
SLaks
Cool... We posted the same answer, at exactly the same time :)
Daniel Vassallo
+2  A: 

You could pass this as an argument:

<p id='foo' onclick='go(this);'>hi</p>

function go(clicked) {
}
Daniel Vassallo