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. #2
    Master Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Behind the Wall
    Thanked 567 Times in 560 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

  3. Users who have thanked Dormilich for this post:

    rygar48 (03-11-2010)

  4. #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Thanked 626 Times in 605 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.
    Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com

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