Bug Tracker

Opened 6 years ago

Closed 5 years ago

Last modified 4 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 6 years ago by rwaldron

  • Owner set to Már Örlygsson
  • Status changed from new to pending

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 6 years ago by rwaldron

  • Resolution set to invalid
  • Status changed from pending to 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 6 years ago by dmethvin

  • Component changed from unfiled to traversing
  • Keywords closest added
  • Priority changed from undecided to low
  • Resolution invalid deleted
  • Status changed from closed to 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 6 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 6 years ago by dmethvin (next)

comment:6 Changed 6 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 6 years ago by snover

  • Milestone 1.5 deleted
  • Status changed from reopened to 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 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 set to 1.next
  • Version changed from 1.4.4rc to 1.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 5 years ago by timmywil

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

comment:13 Changed 5 years ago by timmywil

  • Description modified (diff)

comment:15 Changed 5 years ago by timmywil

#8759 is a duplicate of this ticket.

comment:16 Changed 5 years ago by timmywil

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

comment:17 Changed 5 years ago by john

  • Resolution set to fixed
  • Status changed from assigned to closed

Landed.

Note: See TracTickets for help on using tickets.