#14351 closed bug (fixed)
Exception thrown when running `find` in a non-attached DOM node
Reported by: | Owned by: | gibson042 | |
---|---|---|---|
Priority: | low | Milestone: | 1.11/2.1 |
Component: | selector | Version: | 2.0.3 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
tl;dr
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
Owner: | set to gibson042 |
---|---|
Status: | new → assigned |
comment:2 Changed 9 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
comment:3 Changed 9 years ago by
Milestone: | None → 1.11/2.1 |
---|
comment:4 Changed 9 years ago by
Component: | unfiled → selector |
---|---|
Priority: | undecided → low |
Fix #14351: Update Sizzle