Possible Duplicate:
I trying to get the target element's id when function fired, butthis
keyword returnsundefined
--- HTML file ---
<a href="#link_1" id="id_0" onclick = "getElement('parms1', 'parms2', 'parms3')">0</a>
<a href="#link_2" id="id_1" onclick = "getElement('parms1', 'parms2', 'parms3')">1</a>
<a href="#link_1" id="id_2" onclick = "getElement('parms1', 'parms2', 'parms3')">2</a>
--- Js file ---
function getElement = function(a, b, c){
// trying to get the clicked element
alert(this); // returns 'undefined'
}
Note: I can't modify / add / remove parameters in onclick
function, but I can add / remove parameters in js file
Problem: How to identify that which element was clicked without modifying the onclick
function parameters?