views:

38

answers:

2

It doesn't currently seem as though there is a way to do live events in YUI similar to jQuery: http://api.jquery.com/live/

It sure would be nice if something like:

function handleClick(e) {
    // click!
}

YUI().use('node-base', function(Y) {
    Y.on("click", handleClick, ".foo");
});

caused handleClick to be fired when a node with the "foo" class was clicked on after being dynamically added to the DOM and sometime after the Y.on was evaluated. I feel like live events are one of jQuery's killer features that YUI lacks.

+1  A: 

You can use YUI3's support for event delegation to accomplish the same thing.

YUI().use("node", "event", function(Y) {
    Y.delegate("click", function() {
        //click!
    }, Y.config.win, ".foo");
});

I think attaching that to the window is ok, you might need to attach it to the body instead.

Use Y.one("body") instead of Y.config.win in that case.

Tivac
+1  A: 

YUI 2's Event Utility also supports a delegate method.

wrumsby