Please go through this code.
arrow_left.addEventListener("click",ans_eval);
arrow_right.addEventListener("click",ans_eval); //ans_eval is a function.
now if I want to know which object was clicked, how do I find out?
if(e.target.name==arrow_left){ is this the correct way??
}
How to do it?
When I defined arrow_left, I didn't specify any name for that object, so will e.target.name
work?
You don't need the name, it should work fine just like this:
if ( e.target == arrow_left ) { ...
This of course requires that your method ans_eval
can access to the arrow_left
-variable, meaning that it will be called in the same context and the addEventListener
.
Wether or not this is the case will only you know or you post the whole code in a js-fiddle.