Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-09-2010, 02:10 AM   PM User | #1
rygar48
New to the CF scene

 
Join Date: Mar 2010
Posts: 1
Thanks: 2
Thanked 0 Times in 0 Posts
rygar48 is an unknown quantity at this point
Event handlers vs. event listeners

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...
rygar48 is offline   Reply With Quote
Old 03-09-2010, 03:58 AM   PM User | #2
Dormilich
Senior Coder

 
Dormilich's Avatar
 
Join Date: Jan 2010
Location: Behind the Wall
Posts: 2,907
Thanks: 10
Thanked 293 Times in 289 Posts
Dormilich is on a distinguished road
that depends … (as always)

event handlers are well supported (i.e. work the same in every browser, even IE), but only allow one function.

event listeners allow several functions to be executed, allow event capturing/bubbling, but IE is a pain in the **** here.

event listeners are indeed more powerful/efficient.
__________________
please post your code wrapped in [CODE] [/CODE] tags
Dormilich is offline   Reply With Quote
Users who have thanked Dormilich for this post:
rygar48 (03-11-2010)
Old 03-09-2010, 11:11 PM   PM User | #3
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,553
Thanks: 9
Thanked 480 Times in 463 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
for simple things, i prefer handlers.
for complicated things like trees and grids, listeners allow a single function to monitor the activity of several nodes.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:15.2% IE7:0.5% IE8:8.4% IE9:8.5% IE10:8.5%
rnd me is offline   Reply With Quote
Users who have thanked rnd me for this post:
rygar48 (03-11-2010)
Reply

Bookmarks

Tags
event, handler, javascript, listener

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:12 PM.


Advertisement
Log in to turn off these ads.