Bug Tracker

Ticket #7369 (closed bug: fixed)

Opened 4 years ago

Last modified 3 years ago

$('<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:
Blocking: Blocked by:

Description (last modified by timmywil) (diff)

raises exceptions...

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

does not raise exception...

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

 test case

Change History

comment:1 Changed 4 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:2 Changed 4 years ago by anonymous

comment:3 Changed 4 years ago by rwaldron

  • Status changed from pending to closed
  • Resolution set to invalid

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

  • Keywords closest added
  • Priority changed from undecided to low
  • Status changed from closed to reopened
  • Component changed from unfiled to traversing
  • Resolution invalid deleted

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 4 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 4 years ago by dmethvin (next)

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

  • Status changed from reopened to open
  • Milestone 1.5 deleted

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

comment:8 Changed 4 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 4 years ago by jitter

  • Version changed from 1.4.4rc to 1.5
  • Milestone set to 1.next

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

Confirmed that this bug still present in jQuery 1.5.1

comment:12 Changed 4 years ago by timmywil

  • 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
  • Description modified (diff)
  • Milestone changed from 1.next to 1.6

comment:13 Changed 4 years ago by timmywil

  • Description modified (diff)

comment:14 Changed 4 years ago by timmywil

comment:15 Changed 4 years ago by timmywil

#8759 is a duplicate of this ticket.

comment:16 Changed 4 years ago by timmywil

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

comment:17 Changed 4 years ago by john

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

Landed.

Note: See TracTickets for help on using tickets.