Skip to main content

Bug Tracker

Side navigation

#5877 closed enhancement (invalid)

Opened January 20, 2010 05:06PM UTC

Closed April 17, 2011 12:23AM UTC

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:
Description

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

Attachments (0)
Change History (2)

Changed November 20, 2010 02:45PM UTC by dmethvin comment:1

keywords: event, live, dieneedsreview
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.

Changed April 17, 2011 12:23AM UTC by john comment:2

resolution: → invalid
status: openclosed

Agree with Dave, this is not needed now.