views:

203

answers:

1

jQuery.live

Added in jQuery 1.3: Binds a handler to an event (like click) for all current - and future - matched element. Can also bind custom events.

http://docs.jquery.com/Events/live

Is there a good YUI replacement which can do this?

+5  A: 

In YUI3, delegates perform this function. The following snippet will fire a method called "clickHandler" on any 'p' tag in the body.

YUI().use('event', function(Y) {
  Y.delegate("click", clickHandler, "body", "p");
});

YUI 2.8.0 has delegate functionality as well, but the syntax is slightly different.

foxxtrot
From the docs it looks like unlike jQuery 1.3.2, YUI lets you specify which element in the DOM you want to bind the event delegation to (3rd parameter in your example). Sweet! The selector is the last parameter.
Crescent Fresh
There are a few options. Each YUI3 Node element provides a 'delegate' function, which eliminates the third argument in the example I show above, but the example I show above doesn't require you to instantiate a Node first, which I find convenient sometimes.
foxxtrot