Skip to content

Event Delegation with YUI 3.0

Posted on November 16th, 2009.

Personally I’ve never used the YUI library (yet), but the new event delegation functionality of YUI 3.0 has a very nice look to it:

// Defining simple listeners on each element:
Y.on(“click”, handleClick,
“#container ul li a.profile”);

// Defining listener on a container using the delegate() method:
Y.delegate(‘click’, handleClick,
‘#container’, ‘ul li a.profile’);

[...]

Event delegation in YUI 3 moves the overhead of walking the DOM tree from the loading process to the point of user interaction, and decreases complexity by removing the need to match target elements within the callback. Instead, delegate() tests the event target (e.target) against the selector (‘ul li a.profile’) after the event is fired but before the callback is executed…

More at the YUI Blog.

Add Comment