views:

25

answers:

2

I'm thinking it's a bug, but as of 1.4.2, .live() is supposed to support custom events. Here's a quick little demo: http://jsbin.com/erofi/edit

Is it a bug, or am I doing something wrong with my triggers?

A: 

I don't think you can delegate events to the 'Document'. Not exactly sure, but I think .live() will not bubble up so far.

Try to .bind() and .trigger() to other elements under document.body

Kind Regards

--Andy

jAndy
+1  A: 

.live() must be used on a selector. Whether an event target element matches the selector string is checked at event time. This is hinted at in the doc ‘caveats’:

DOM traversal methods are not fully supported for finding elements to send to .live(). Rather, the .live() method should always be called directly after a selector, as in the example above.

$(document) isn't a selector. If you look at $(document).selector, which is the remembered selector string that live() uses for matching, you get an empty string, hence live() not working.

Since selectors only match elements, you can't live-bind against document. Then again, since document never changes, there is no need to: a normal binding would be fine.

(This is unfortunate API design. It should have been $.live('selector', 'event', function() {}); IMO. $('selector').live() makes it unclear what it's actually doing. And certainly there should have been an error when you call live() on a wrapper without a selector.)

bobince
That is why .delegate() was introduced, works 'better' and makes things a lot more clear
jAndy
thanks for the clear answer
Jason