MooTools Event Delegation

By  on  

One feature I heard Moo developers hinting at was the future addition of event delegation to the MooTools JavaScript library. MooTools Core Developer, Aaron Newton, wrote a post today about a plugin he's created that does just that.

From the article:

Event delegation is a common practice where by you attach an event listener to a parent object to monitor its children rather than attach events to all the children. It's far more efficient when you have numerous items on a page that you want to interact with.

I don't know of any concrete plans to incorporate this functionality into MooTools 1.3 but I assume they will. I strongly suggest MooTools developers read Aaron's article at Clientcide. I also recommend this article for jQuery users as John Resig recently boasted of this addition to jQuery.

Exciting times in the framework world!

Recent Features

Incredible Demos

  • By
    Form Element AJAX Spinner Attachment Using MooTools

    Many times you'll see a form dynamically change available values based on the value of a form field. For example, a "State" field will change based on which Country a user selects. What annoys me about these forms is that they'll often do an...

  • By
    WebKit Marquee CSS:  Bringin’ Sexy Back

    We all joke about the days of Web yesteryear.  You remember them:  stupid animated GIFs (flames and "coming soon" images, most notably), lame counters, guestbooks, applets, etc.  Another "feature" we thought we had gotten rid of was the marquee.  The marquee was a rudimentary, javascript-like...

Discussion

  1. John Resig, boasting!? GASP!

    Thanks for the news David! … I’ve never been a fan of delegated events/event handlers – do they even bubble/propogate?

  2. Let me add that event delegation is awesome when you’re continually adding DOM elements, perhaps via Ajax… I’m just not sure the performance benefits are as they seem.

  3. @James: I didn’t mean “boasted” in a bad way. It’s an awesome addition which should be boasted. You can find the answer to your question here:

    http://groups.google.com/group/mootools-users/browse_thread/thread/bbaf247948273868/db6a33205b71c89b?show_docid=db6a33205b71c89b

  4. Daniel

    James, believe me with even a couple hundred elements you can see a big difference. It takes a few more elements to make a browser like Chrome slow up, but IE folks will see the difference on smaller numbers of events like night and day.

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!