PDA

View Full Version : Event handler vs. event listener


Rygar48
9th March 10, 01:02 AM
Hey everyone, so I am in the process of learning Javascript via e-book (not the best way, I know, but it's how I learned PHP, so I thought it would do. The book I'm reading is "Simply Javascript") but I'm a little confused on event handlers vs. event listeners.

Someone told me that event listeners are to add the possibility of an event onto something that doesn't already have a listener on it, whereas a handler would be used to handle something that already has a listener on it (i.e a link). But in this book, it says that event listeners are to always be used, as they are more efficient/powerful than handlers. In their examples, they even use a listener on a link.

SO, what's the difference/which should I use? Handlers seem much easier...

meesa
9th March 10, 04:55 AM
Sounds like an event listner would be: onclick="JSScript()" whereas an event handler would be JSScript(), the function that handles what happens then the event (onclick) happens.

chrishirst
12th March 10, 09:50 AM
event handlers (http://javascript.about.com/library/bldom16.htm) & event listeners (http://javascript.about.com/library/bldom19.htm)