#7369 closed bug (fixed)
$('<div>ff</div>').closest('[attr]'); raises exception in all browsers
| Reported by: | Már Örlygsson | Owned by: | timmywil |
|---|---|---|---|
| Priority: | low | Milestone: | 1.6 |
| Component: | traversing | Version: | 1.5 |
| Keywords: | closest | Cc: | |
| Blocked by: | Blocking: |
Description (last modified by )
raises exceptions...
$('<div>ff</div>').closest('[foo]')
$('<div anyAttr></div>').closest('[foo]')
does not raise exception...
$('<div></div>').closest('[foo]')
Change History (16)
comment:1 Changed 9 years ago by
| Owner: | set to Már Örlygsson |
|---|---|
| Status: | new → pending |
comment:3 Changed 9 years ago by
| Resolution: | → invalid |
|---|---|
| Status: | pending → closed |
You can't call closest() on a document fragment that hasn't actually been appended into the DOM. You CAN create and append an element and then call it:
http://jsfiddle.net/rwaldron/PjbQA/1/
This is not a jQuery bug.
comment:4 Changed 9 years ago by
| Component: | unfiled → traversing |
|---|---|
| Keywords: | closest added |
| Priority: | undecided → low |
| Resolution: | invalid |
| Status: | closed → reopened |
Seems like it should be possible to use .closest() on disconnected nodes, and in general it is except for this case with attributes.
comment:5 Changed 9 years ago by
OK, I got this in the IE8 debugger. The problem is that Sizzle walks up to the document and then in ATTR tries to call elem.getAttribute("lang") but there is no getAttribute method on document. I guess we could check for elem.getAttribute being present?
Perhaps the bigger question is how we get to the document on a disconnected element...
comment:6 Changed 9 years ago by
Checking for getAttribute being present sounds like a good fix.
Please try to gt this fix into 1.4.4
comment:7 Changed 9 years ago by
| Milestone: | 1.5 |
|---|---|
| Status: | reopened → open |
There is no document on a disconnected node; at best only a fragment (nodeType 11). This is very similar to #7142.
comment:8 Changed 9 years ago by
This is still broken in jQuery 1.5
Ticket #7142 did not fix this one.
comment:9 Changed 9 years ago by
| Milestone: | → 1.next |
|---|---|
| Version: | 1.4.4rc → 1.5 |
comment:12 Changed 9 years ago by
| Description: | modified (diff) |
|---|---|
| Milestone: | 1.next → 1.6 |
| Owner: | changed from Már Örlygsson to timmywil |
| Status: | open → assigned |
| Summary: | `$('<div>ff</div>').closest('[attr]');` crashes on MSIE → $('<div>ff</div>').closest('[attr]'); raises exception in all browsers |
comment:13 Changed 9 years ago by
| Description: | modified (diff) |
|---|
comment:16 Changed 9 years ago by
The pull request does not fix this issue when doing $('<div>text</div>').after(...)

Thanks for taking the time to contribute to the jQuery project! Please provide a reduced jsFiddle test case, thanks again - and party on!
Please help me understand what you're trying to accomplish - the example you've given is actually invalid.
Additionally, test against the jQuery 0 GIT version to ensure the issue still exists. Be Excellent to eachother!