Possible Duplicate:
How do you find out the caller function in JavaScript?
I have the following code:
JS:
function myfunc(mynumber){
console.log(mynumber);
}
HTML:
<div onclick="myfunc(5);"></div>
Is there a way, with jQuery, to be able to get the context of that element that was clicked inside the myfunc function, without passing this or $(this) as a parameter in the onclick attribute?
I’d use jQuery to actually bind the event handler, that way
thisinside that function will refer to the element that triggered the event. You can use a HTML5data-*attribute to store the number that you want to use for that particular element.HTML
jQuery