Bug Tracker

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#14351 closed bug (fixed)

Exception thrown when running `find` in a non-attached DOM node

Reported by: [email protected] Owned by: gibson042
Priority: low Milestone: 1.11/2.1
Component: selector Version: 2.0.3
Keywords: Cc:
Blocked by: Blocking:



The following snippet throws an exception in jQuery from version 1.8.3 and forward:

$('<div><a></a></div>').find(':not(:hidden) + c , d')

The exception reads:

Cannot read property '0' of undefined

When asking JSFiddle to use jQuery version 1.x/2.x, the message changes to:

Cannot read property 'length' of undefined

If appending the new element to another node, it works fine:

$('<div><a></a></div>').appendTo('<div>').find(':not(:hidden) + c , d')

More details

Testing in JSFiddle (http://jsfiddle.net/cpxbb/), it worked in jQuery 1.7.2 and started failing in jQuery 1.8.3.

The error message changed nature between 1.9.1/2.0.2 and the 1.x/2.x versions (JSFiddle does not currently have any specific versions above 1.9.1/2.0.2).

I debugged a bit through the minified version of 1.8.3, and it fails at a point where it tries to find tags based on the parentNode of the root element, which is a document-fragment for an unattached element.

The call that returned undefined is:

i.find.TAG("*", h && a.parentNode || a)

where a is the top element (the div in the example code).

An immediate work-around is to attach the node to a dummy-element before running the find operation.

Change History (4)

comment:1 Changed 9 years ago by gibson042

Owner: set to gibson042
Status: newassigned

comment:2 Changed 9 years ago by Richard Gibson

Resolution: fixed
Status: assignedclosed

Fix #14351: Update Sizzle

Changeset: 1d57ffe5fff06928aac53813342d33ec6bddd531

comment:3 Changed 9 years ago by dmethvin

Milestone: None1.11/2.1

comment:4 Changed 9 years ago by dmethvin

Component: unfiledselector
Priority: undecidedlow
Note: See TracTickets for help on using tickets.