Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    1
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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...

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,342
    Thanks
    13
    Thanked 349 Times in 345 Posts
    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.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • Users who have thanked Dormilich for this post:

    rygar48 (03-11-2010)

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,373
    Thanks
    11
    Thanked 592 Times in 572 Posts
    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 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • Users who have thanked rnd me for this post:

    rygar48 (03-11-2010)


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •