Bug Tracker

Opened 13 years ago

Closed 12 years ago

#5877 closed enhancement (invalid)

jQuery.live() - compliment to jQuery.fn.live()

Reported by: jmar777 Owned by: brandon
Priority: low Milestone:
Component: event Version: 1.4
Keywords: needsreview Cc:
Blocked by: Blocking:


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

Change History (2)

comment:1 Changed 12 years ago by dmethvin

Keywords: needsreview added; event live die removed
Milestone: 1.4.1
Priority: majorlow
Status: newopen

Now that we have .delegate(), is this needed at all? I like the fact that .delegate() makes the delegation point explicit.

comment:2 Changed 12 years ago by john

Resolution: invalid
Status: openclosed

Agree with Dave, this is not needed now.

Note: See TracTickets for help on using tickets.