Ticket #5877 (closed enhancement: invalid)
jQuery.live() - compliment to jQuery.fn.live()
|Reported by:||jmar777||Owned by:||brandon|
This is a proposal for a jQuery.live() implementation with the following method signature:
jQuery.live( selector, [context], eventType, [eventData], handler );
While the current jQuery.fn.live/die implementations feel natural within the normal flow jQuery coding, the jQuery.fn namespacing carries certain implications that I do not believe are best applied to event delegation.
These are my primary concerns:
- jQuery.fn methods are almost entirely "find something, do something" utilities. They operate on an existing set of nodes that have already been queried. Live(), on the other hand, by nature of using event delegation, does not follow this pattern.
While the actual implementation should be abstracted, this is an important distinction that I don't believe the API should necessarily blur.
- Although generally cheap, $(selector, context).live(...) requires actually querying for the matching elements, even though they are not required. This strikes me as somewhat of an anti-pattern, or at least something that could optionally be avoided.
- There is the potential for new jQuery developers to be confused as to what live() is ultimately doing, which can lead to abuse/misuse/etc...
While I have no desire to break the existing API, I believe that complimentary live/die implementations would be a positive enhancement to jQuery's event management (for all the reasons stated above).
I have made a sample implementation of what I am describing here (including unit tests): http://github.com/jmar777/jquery/commits/jQuery.live
It is worth noting that David Furferohas has also (previously) created a similar implementation: http://github.com/furf/jquery-live