Sounds like a wrong approach. You don't need to know which one is clicked, you need to handle the click differently depending on what the use clicks. Do you see the difference?
So, you just install some handler for some elements, some different handler for other elements:
function someClickHandler() {
}
function someOtherHandler() {
}
oneElement.onclick = someClickHandler;
anotherElement.onclick = someOtherHandler;
Additionally, you can pass event object and find the target element using the property
target
:
oneElement.onclick = someClickHandler;
function someClickHandler(ev) {
if (ev.target === oneElement)
alert("you passed reference to the element clicked");
}
—SA