brandonaaron / livequery

MIT License
477 stars 195 forks source link

Use jQuery 1.4 .live() when possible #7

Closed shadowhand closed 10 years ago

shadowhand commented 13 years ago

Would it make sense for livequery to call .live() for events that .live() can support directly, such as click, submit, etc?

Also, would it be more efficient to refactor livequery to use .live() (with custom .bind() events) internally?

alexweber commented 13 years ago

Interesting... I'd like to know about this too!

eych commented 13 years ago

The code which you bind with live() to an element's event is only executed when the bound event is triggered on the page on that element.

The core difference of livequery() is that it allows you to execute your code when the element is only being added to the page. So there shouldn't even be any event as such that is triggered, for example, you can show a message to the user each time an element matching a specific selector is added to the page (not that this is a useful example, just to illustrate the difference).

You can't do this kind of thing with live() at all.

shadowhand commented 13 years ago

you can show a message to the user each time an element matching a specific selector is added to the page ... You can't do this kind of thing with live() at all.

I am completely aware of that. However, something like .livequery('click', ...) should translate directly to .live('click', ...), unless I am missing something.

mikesherov commented 13 years ago

@shadowhand you are correct. This plugin was created before live() existed, and can be drastically reduced if it were to fallback to .live() for the cases you mentioned. For the record, jQuery was introduced in 1.3, so it's safe to assume that anyone updating to the newest version of livequery would be running 1.3+, but if we wanted to be extra cautious, you could apply have a fallback.

brandonaaron commented 10 years ago

Sorry for taking 3 years to reply to this thread. The livequery plugin is currently being rewritten and part of that is to completely remove the event related functionality and focus solely on the DOM manipulations.