Bug Tracker

Opened 7 years ago

Closed 6 years ago

Last modified 5 years ago

#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 timmywil)

raises exceptions...

$('<div>ff</div>').closest('[foo]')
$('<div anyAttr></div>').closest('[foo]')

does not raise exception...

$('<div></div>').closest('[foo]')

test case

Change History (16)

comment:1 Changed 7 years ago by Rick Waldron

Owner: set to Már Örlygsson
Status: newpending

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!

comment:3 Changed 7 years ago by Rick Waldron

Resolution: invalid
Status: pendingclosed

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 7 years ago by dmethvin

Component: unfiledtraversing
Keywords: closest added
Priority: undecidedlow
Resolution: invalid
Status: closedreopened

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 7 years ago by dmethvin

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?

Version 0, edited 7 years ago by dmethvin (next)

comment:6 Changed 7 years ago by Már Örlygsson <mar.nospam@…>

Checking for getAttribute being present sounds like a good fix.

Please try to gt this fix into 1.4.4

comment:7 Changed 7 years ago by snover

Milestone: 1.5
Status: reopenedopen

There is no document on a disconnected node; at best only a fragment (nodeType 11). This is very similar to #7142.

comment:8 Changed 6 years ago by Már Örlygsson <mar.nospam@…>

This is still broken in jQuery 1.5

Ticket #7142 did not fix this one.

comment:9 Changed 6 years ago by jitter

Milestone: 1.next
Version: 1.4.4rc1.5

comment:10 Changed 6 years ago by Már Örlygsson <mar.nospam@…>

Confirmed that this bug still present in jQuery 1.5.1

comment:12 Changed 6 years ago by timmywil

Description: modified (diff)
Milestone: 1.next1.6
Owner: changed from Már Örlygsson to timmywil
Status: openassigned
Summary: `$('<div>ff</div>').closest('[attr]');` crashes on MSIE$('<div>ff</div>').closest('[attr]'); raises exception in all browsers

comment:13 Changed 6 years ago by timmywil

Description: modified (diff)

comment:15 Changed 6 years ago by timmywil

#8759 is a duplicate of this ticket.

comment:16 Changed 6 years ago by timmywil

The pull request does not fix this issue when doing $('<div>text</div>').after(...)

comment:17 Changed 6 years ago by john

Resolution: fixed
Status: assignedclosed

Landed.

Note: See TracTickets for help on using tickets.