If the HTML is like:
<a href="javascript:void(0)" id="link">Click Me</a>
and I set the eventHandler for click as
ele.addEventListener('click', clickme, false);
What’s the pretty standard way of getting the value of ele in handler.
I succeed getting the value of ele in chrome by: (working example – http://jsfiddle.net/hy5Pz/4/ )
function clickme(e){
var ele = e.toElement;
ele.innerText = "I got clicked";
}
and in Firefox by: (working example – http://jsfiddle.net/hy5Pz/3/ )
function clickme(e){
var ele = e.rangeParent;
ele.data="I got clicked";
}
I am new to JavaScript so I want to know if there is a pretty standard cross-useragent way of doing it.
I believe
Will work in most browsers. It basically tries to use
e.targetfirst, and if that’s not found, usee.srcElementinstead.e.targetis used in good browsers,e.srcElementin IE.