Skip to main content

Bug Tracker

Side navigation

#11993 closed bug (duplicate)

Opened June 29, 2012 10:09AM UTC

Closed June 29, 2012 02:05PM UTC

Last modified June 29, 2012 02:05PM UTC

Delegate(":PositionalSelector") non-deterministic within widgets

Reported by: syndicatedshannon Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.2
Keywords: Cc:
Blocked by: Blocking:
Description

I previously used:

$("#widget").
  delegate("input:last", "change", handler);

It worked for me in 1.4.4, but does not in 1.7.2 (if the widget does not contain the last input on the page).

I see a couple tickets requesting the selector to apply to the delegated element's context (#10762, #6696), although they are closed due to the invalid child selector usage. I don't want to wade into that battle, so I'm talking specifically about the selector context, not the use of the CSS child selector.

I'll be honest, I remember when I first wrote this code a year or two ago I wondered if the context would be valid. I tested it skeptically.

But I've used it quite a bit since then, and I think it makes sense for several reasons:

  • $("table tr:even").click is a pretty common sort of sort of thing you'd want to be able to delegate in a templated/AJAX document.
  • Using the document context diminishes the performance of the is() evaluation in question, for potentially significantly for frequent events in large documents. This could be a significant detractor for another scenario for replacing traditional multi-element.
  • The current functionality is less deterministic than the previous.
  • Not using the delegated element's context makes a number of useful jQuery selectors non-deterministic within page widgets, devaluing useful jQuery code.
  • It worked differently in the original implementation of delegate.
  • It seems to follow the spirit of jQuery context better, both from the standpoint of the event handler the delegate is replacing, and the broader usage of context in general (where specificity is not 'lost' when possible).
  • Requiring the parent selectors to be repeated both on the delegated element's selector and in the delegate function call makes for less DRY code.
  • The discussion in prior tickets seemed to agree that the selector context was sensible, even if the use of the CSS child selector wasn't.

I don't understand why v. 1.7.2 line 3285 says:

jqcur.context = this.ownerDocument || this;

since I don't understand it, I didn't pretend to 'fix' it. Sorry to not contribute more than this defect report.

Attachments (0)
Change History (5)

Changed June 29, 2012 10:44AM UTC by syndicatedshannon comment:1

Also related: #10563

Changed June 29, 2012 11:02AM UTC by syndicatedshannon comment:2

p.s. I'll add a jsfiddle when it's back online.

Changed June 29, 2012 11:40AM UTC by syndicatedshannon comment:3

_comment0: [http://jsfiddle.net/dWJ2M jsfiddle on 1.7.2 (doesn't work)] \ [http://jsfiddle.net/dWJ2M/1 jsfiddle on 1.6.4 (works)]1340970977932913

Changed June 29, 2012 02:05PM UTC by dmethvin comment:4

resolution: → duplicate
status: newclosed

Works in 1.8beta: http://jsfiddle.net/dWJ2M/2/

Changed June 29, 2012 02:05PM UTC by dmethvin comment:5

Duplicate of #11315.