Side navigation
#7369 closed bug (fixed)
Opened November 01, 2010 02:00PM UTC
Closed April 10, 2011 08:48PM UTC
Last modified March 13, 2012 03:07PM UTC
$('<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
raises exceptions...
$('<div>ff</div>').closest('[foo]') $('<div anyAttr></div>').closest('[foo]')
does not raise exception...
$('<div></div>').closest('[foo]')
Attachments (0)
Change History (16)
Changed November 01, 2010 02:17PM UTC by comment:1
owner: | → Már Örlygsson |
---|---|
status: | new → pending |
Changed November 01, 2010 04:15PM UTC by comment:2
Changed November 01, 2010 05:39PM UTC by comment:3
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.
Changed November 03, 2010 10:34PM UTC by comment:4
component: | unfiled → traversing |
---|---|
keywords: | → closest |
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.
Changed November 04, 2010 12:25AM UTC by comment:5
_comment0: | 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? → 1288830876004642 |
---|
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...
Changed November 04, 2010 02:30PM UTC by comment:6
Checking for getAttribute
being present sounds like a good fix.
Please try to gt this fix into 1.4.4
Changed November 07, 2010 09:21PM UTC by comment:7
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.
Changed February 02, 2011 05:10PM UTC by comment:8
This is still broken in jQuery 1.5
Ticket #7142 did not fix this one.
Changed February 02, 2011 11:05PM UTC by comment:9
milestone: | → 1.next |
---|---|
version: | 1.4.4rc → 1.5 |
Changed February 24, 2011 10:46PM UTC by comment:10
Confirmed that this bug still present in jQuery 1.5.1
Changed March 31, 2011 02:00AM UTC by comment:11
description: | This piece of code causes a crash on MSIE 8>... \ {{{ \ $('<div>ff</div>').closest('[foo]') \ }}} \ → raises exceptions... \ {{{ \ $('<div>ff</div>').closest('[foo]') \ $('<div anyAttr></div>').closest('[foo]') \ }}} \ \ does not raise exception... \ {{{ \ $('<div></div>').closest('[foo]') \ }}} \ |
---|---|
milestone: | 1.next → 1.6 |
owner: | Már Örlygsson → timmywil |
status: | open → assigned |
summary: | `$('<div>ff</div>').closest('[attr]');` crashes on MSIE → $('<div>ff</div>').closest('[attr]'); raises exception in all browsers |
Changed March 31, 2011 02:06AM UTC by comment:12
description: | raises exceptions... \ {{{ \ $('<div>ff</div>').closest('[foo]') \ $('<div anyAttr></div>').closest('[foo]') \ }}} \ \ does not raise exception... \ {{{ \ $('<div></div>').closest('[foo]') \ }}} \ → raises exceptions... \ {{{ \ $('<div>ff</div>').closest('[foo]') \ $('<div anyAttr></div>').closest('[foo]') \ }}} \ \ does not raise exception... \ {{{ \ $('<div></div>').closest('[foo]') \ }}} \ \ [http://jsfiddle.net/timmywil/PjbQA/5/ test case] \ |
---|
Changed April 01, 2011 12:25AM UTC by comment:13
Changed April 04, 2011 02:32PM UTC by comment:14
#8759 is a duplicate of this ticket.
Changed April 04, 2011 02:33PM UTC by comment:15
The pull request does not fix this issue when doing $('<div>text</div>').after(...)
Changed April 10, 2011 08:48PM UTC by comment:16
resolution: | → fixed |
---|---|
status: | assigned → closed |
Landed.
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!