Hello and welcome to our community! Is this your first visit?
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
    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
    Behind the Wall
    Thanked 387 Times in 383 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
    Thanked 608 Times in 588 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 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • 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