Ticket #10726 (closed bug: fixed)
$(#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: |
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]')
Change History
comment:2 Changed 19 months 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 19 months 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 19 months ago by timmywil
- Priority changed from undecided to low
- Component changed from unfiled to traversing
This may be related: https://github.com/jquery/sizzle/pull/79
comment:5 Changed 19 months ago by cwolves
nope, that's a different issue.
Simplified use case:
$('<iframe></iframe>').appendTo(document.body).contents().attr('foo')
comment:6 Changed 19 months 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:8 Changed 10 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.

IE8