Bug Tracker


Ticket #10726 (closed bug: fixed)

Opened 2 years ago

Last modified 21 months ago

$(#document).closest('[foo]') throws error in IE

Reported by: cwolves Owned by: timmywil
Priority: low Milestone: None
Component: selector Version:
Keywords: Cc:
Blocking: Blocked by:


Trying to access properties of what I think is a document fragment (nodeName === '#document' ) throws an error in IE:

Object doesn't support property or method 'getAttribute'

The code triggering this is $('iframe').contents().closest('[foo]')

Change History

comment:1 Changed 2 years ago by cwolves


comment:2 Changed 2 years ago by dmethvin

  • Owner set to cwolves
  • Status changed from new to pending

Can you provide a simple reduced test case?

What is the use case for this? Closest is going to look up from the .contents() and that doesn't even seem useful.

comment:3 Changed 2 years ago by cwolves

  • Status changed from pending to new

the $('iframe').contents() piece is coming from a 3rd party plugin. I'm doing $node.closest('[foo]') for a separate purpose, I'm just getting a #document node.

comment:4 Changed 2 years ago by timmywil

  • Priority changed from undecided to low
  • Component changed from unfiled to traversing

comment:5 Changed 2 years ago by cwolves

nope, that's a different issue.

Simplified use case:


Version 0, edited 2 years ago by cwolves (next)

comment:6 Changed 2 years ago by timmywil

  • Owner changed from cwolves to timmywil
  • Status changed from new to assigned

@cwolves, I still wouldn't rule it out. .closest uses matchesSelector and calling matchesSelector on a document should be fine.  http://jsfiddle.net/timmywil/qa29b/

Calling matchesSelector on an iframe document while trying to access an attribute could be a problem, but I will look into it more.

comment:7 Changed 22 months ago by dmethvin

  • Component changed from traversing to selector

comment:8 Changed 21 months ago by Timmy Willison

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

Fail silently if closest is somehow called on a document. Fixes #10726.

Changeset: 17a26f5bd9b14225248942b876e96545b4c21fb6

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.


Add a comment

Modify Ticket

as closed

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.