Skip to main content

Bug Tracker

Side navigation

#12054 closed bug (fixed)

Opened July 10, 2012 11:15PM UTC

Closed July 11, 2012 09:23PM UTC

Uncaught TypeError: Object #<HTMLDocument> has no method 'getAttribute'

Reported by: musicisair@yahoo.com Owned by: gibson042
Priority: high Milestone: 1.8
Component: selector Version: 1.8b2
Keywords: Cc:
Blocked by: Blocking:
Description

$(document).is(".something");​ will throw Uncaught TypeError: Object #<HTMLDocument> has no method 'getAttribute'

http://jsfiddle.net/musicisair/aUB7P/

tested on Chrome 20.0.1132.47 m

Attachments (0)
Change History (9)

Changed July 11, 2012 12:58AM UTC by dmethvin comment:1

owner: → musicisair@yahoo.com
status: newpending

So what should we do about that? Are you looking for argument-specific error messages regarding all invalid inputs?

Error: this method does not take a document
Error: this method does not take a window
Error: this method does not take a plain object
Error: this method does not take a text node

http://jsfiddle.net/AvgFU/

Changed July 11, 2012 01:32AM UTC by mikesherov comment:2

Document is never something. Insane inputs yield insane results.

Changed July 11, 2012 03:39PM UTC by musicisair comment:3

I know it is pointless to check if a document matches a class (or pretty much anything, really).

BUT ... It worked *as expected* in jQuery 1.8b1 and 1.7.2 (and probable many more versions).

Check http://jsfiddle.net/tQKZ7/1/ for a little context and my use case.

@dmethvin, All those cases work in 1.7.2: http://jsfiddle.net/AvgFU/1/

I'm all for jQuery being a little less forgiving when it comes to invalid input; however, since we often do things like $(event.target) and event.target can be a document, document should probably be supported here, IMO.

Also, in 1.8b2 (et al.):

$(document).is(document) === true

$(document).is("div") === false

$(document).is("[attr]") === false

Changed July 11, 2012 03:46PM UTC by dmethvin comment:4

component: unfiledselector
milestone: None1.8
priority: undecidedhigh
status: pendingopen

All of that detail is missing from the original report, @musicair. It's helpful to state that you're reporting a regression, even if it's with invalid inputs, and what you'd like the actual behavior to be. I see your point on things like $(event.target) so I'll mark this open and we can discuss.

Changed July 11, 2012 03:48PM UTC by rwaldron comment:5

owner: musicisair@yahoo.comtimmywil
status: openassigned

Blitzed!

This is a regression caused by the Sizzle rewrite.

Changed July 11, 2012 04:59PM UTC by David Murdoch <musicisair@yahoo.com> comment:6

@dmethvin I guess I reduced the test case a little too far. I was assuming that any bug reports against a beta version would be for regressions, and that you all would assume the same. Sorry.

Honestly, I thought that document was valid input and that it was obvious that the example given should work. Which is why the ticket was so concise.

Related: http://bugs.jquery.com/ticket/10178

Changed July 11, 2012 07:33PM UTC by dmethvin comment:7

@musicair, definitely thanks for reporting it, I just didn't realize the context. We're already getting quite a few related reports like plugins doing $(-1).is(".jstree") and expecting a casual false reply. So as much as I'd like to keep at least some of those things in the totally invalid category it seems that we'd fill the bug tracker with complaints if we didn't change it back.

Changed July 11, 2012 08:15PM UTC by gibson042 comment:8

owner: timmywilgibson042

Changed July 11, 2012 09:23PM UTC by Dave Methvin comment:9

resolution: → fixed
status: assignedclosed

Update Sizzle; Closes #12054, #12057.

Changeset: 0bde43aeee5bed5fdfb5bffaecb8c1f43c8fdf19