Your question seems to be about the meaning of this . In the built-in handler, this will represent window . You can set this value with .call() so that it gives the desired value.
Example: http://jsfiddle.net/patrick_dw/5uJ54/
<button id="clicker" onclick="click.call(this)" >Click me</button>
Your click this method will this have a <button> element.
The reason is because your inline attribute is wrapped in a function that itself has an element context. But this does not actually call your function from this context. By executing click() , it looks like this:
function onclick(event) { click(); }
Your function is called against any particular object, so window implied. Performing:
<button id="clicker" onclick="click.call( this )" >Click me</button>
... You'll get:
function onclick(event) { click.call( this ); }
Providing the desired context. You can also pass an event object:
<button id="clicker" onclick="click.call( this, event )" >Click me</button>
... so you end up with:
function onclick(event) { click.call( this, event ); }
So, now in your click() function you will have event , as you would expect.
In addition, you may experience problems using click as the function name. I would change it.
source share