Bug Tracker

Opened 11 years ago

Closed 11 years ago

#12054 closed bug (fixed)

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

Reported by: musicisair@… 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

Change History (9)

comment:1 Changed 11 years ago by dmethvin

Owner: set to musicisair@…
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/

comment:2 Changed 11 years ago by mikesherov

Document is never something. Insane inputs yield insane results.

comment:3 Changed 11 years ago by musicisair

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

comment:4 Changed 11 years ago by dmethvin

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.

comment:5 Changed 11 years ago by Rick Waldron

Owner: changed from musicisair@… to Timmy Willison
Status: openassigned

Blitzed!

This is a regression caused by the Sizzle rewrite.

comment:6 Changed 11 years ago by David Murdoch <musicisair@…>

@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

comment:7 Changed 11 years ago by dmethvin

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

comment:8 Changed 11 years ago by gibson042

Owner: changed from Timmy Willison to gibson042

comment:9 Changed 11 years ago by Dave Methvin

Resolution: fixed
Status: assignedclosed

Update Sizzle; Closes #12054, #12057.

Changeset: 0bde43aeee5bed5fdfb5bffaecb8c1f43c8fdf19

Note: See TracTickets for help on using tickets.