If you’re going to hardcode event handlers right into your HTML, (perhaps its being delivered from a php page) there’s 2 ways you can do this:
<span onclick=” runFuncAndTargetIsTHIS( this ); “> <!– way A –>
or:
<span onclick=” runFuncButNeedToExtractTarget( event ); “> <!– way B –>
Function for way A looks like:
runFuncAndTargetIsTHIS( elem )
{
alert( elem + ' is the HTML element that was clicked' );
}
While way B:
runFuncButNeedToExtractTarget( e )
{
e = e || window.event;
var target = e.target || e.srcElement;
alert( target + ' is the HTML element that was clicked' );
}
Some people say you shouldn’t do things using Way A. But I find Way A sometimes convenient. The only reason I can think of right now that Way A is bad is its easier to cancel propagation (cancel bubbling) of event registered using way B.