Skip to main content

Bug Tracker

Side navigation

#10726 closed bug (fixed)

Opened November 08, 2011 08:25PM UTC

Closed July 25, 2012 08:06PM UTC

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

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

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]')

Attachments (0)
Change History (8)

Changed November 08, 2011 08:26PM UTC by cwolves comment:1

IE8

Changed November 08, 2011 08:51PM UTC by dmethvin comment:2

owner: → cwolves
status: newpending

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.

Changed November 08, 2011 09:05PM UTC by cwolves comment:3

status: pendingnew

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.

Changed November 08, 2011 09:16PM UTC by timmywil comment:4

component: unfiledtraversing
priority: undecidedlow

Changed November 08, 2011 09:30PM UTC by cwolves comment:5

_comment0: nope, that's a different issue. \ \ Simplified use case: \ \ $('<iframe></iframe>').appendTo(document.body).contents().get(0).attr('foo')1320787870773045
_comment1: nope, that's a different issue. \ \ Simplified use case: \ \ $('<iframe></iframe>').appendTo(document.body).contents().attr('foo')1320787917336996

nope, that's a different issue. Don't think it's iframes specifically, just the #document node

Changed November 08, 2011 09:52PM UTC by timmywil comment:6

owner: cwolvestimmywil
status: newassigned

@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.

Changed July 12, 2012 01:47AM UTC by dmethvin comment:7

component: traversingselector

Changed July 25, 2012 08:06PM UTC by Timmy Willison comment:8

resolution: → fixed
status: assignedclosed

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

Changeset: 17a26f5bd9b14225248942b876e96545b4c21fb6