Bug Tracker

Ticket #12054 (closed bug: fixed)

Opened 2 years ago

Last modified 2 years ago

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:
Blocking: Blocked by:

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

comment:1 Changed 2 years ago by dmethvin

  • Owner set to musicisair@…
  • Status changed from new to pending

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 2 years ago by mikesherov

Document is never something. Insane inputs yield insane results.

comment:3 Changed 2 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 2 years ago by dmethvin

  • Priority changed from undecided to high
  • Status changed from pending to open
  • Component changed from unfiled to selector
  • Milestone changed from None to 1.8

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 2 years ago by rwaldron

  • Owner changed from musicisair@… to timmywil
  • Status changed from open to assigned

Blitzed!

This is a regression caused by the Sizzle rewrite.

comment:6 Changed 2 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 2 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 2 years ago by gibson042

  • Owner changed from timmywil to gibson042

comment:9 Changed 2 years ago by Dave Methvin

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

Update Sizzle; Closes #12054, #12057.

Changeset: 0bde43aeee5bed5fdfb5bffaecb8c1f43c8fdf19

Note: See TracTickets for help on using tickets.