[Javascript] Differences with event handlers

Peter Brunone peter at brunone.com
Mon Jul 12 09:27:20 CDT 2010


Do you have to use an anchor at all?  Why not just a div or button?  That 
way there's no default behavior that you have to cancel... or are you 
trying to plan for js-less clients?

----------------------------------------
 From: "Terry Riegel" <riegel at clearimageonline.com>
Sent: Monday, July 12, 2010 8:51 AM
To: "JavaScript List" <javascript at lists.evolt.org>
Subject: [Javascript] Differences with event handlers

Hello All,

I have an issue with event handlers and am not sure how to resolve it...

I can handle a click event for an anchor one of two ways...

1. anchorObj.addEventListener( 'click', fn, false ); // or attachEvent

or

2. anchorObj.onclick=fn;

With the second method I can "return false;" from fn and it stops the 
browser from doing the normal thing, but with the addEventListener it still 
sends the anchor.

What is the best way to get the first method to work like the second one.

Thanks,

Terry


More information about the Javascript mailing list