Bug Tracker

Opened 10 years ago

Closed 10 years ago

Last modified 8 years ago

#7577 closed bug (invalid)

TypeError: "query is undefined" is thrown for .find(undefined)

Reported by: barberboy@… Owned by:
Priority: undecided Milestone: 1.5
Component: unfiled Version: 1.4.4
Keywords: Cc:
Blocked by: Blocking:


When the first argument to .find() is 'undefined', an error is thrown instead of returning a jQuery object with no elements. The error is:

TypeError: "query is undefined"

This regression is caused by a recent change to Sizzle to quote attribute selectors: https://github.com/jeresig/sizzle/commit/aa6076c6a2b79acd2f8c67592f91206bbcb08f03


var a = {}; jQuery(document).find(a.foo);

Change History (3)

comment:1 Changed 10 years ago by jitter

Resolution: invalid
Status: newclosed

Thanks for taking the time to contribute to the jQuery project by writing a bug report!

After looking into this I determined that passing undefined to find() isn't a valid thing to do (besides not making much sense). The find API doc states

... the selector expression is required in a call to .find()

If you have an application where you can prevent such things from happening (e.g. you don't control what gets passed to find()) you can use something like

.find(a.foo || "") to always have a valid selector.

Last edited 10 years ago by jitter (previous) (diff)

comment:2 in reply to:  1 Changed 10 years ago by barberboy@…

Hey jitter, thanks for looking into this issue!

I'm concerned about this issue because it is a regression that breaks backwards compatibility with 1.4.3 and is incorrect behavior according to the documentation on .find().

The API documentation for .find() says "The method accepts a selector expression of the same type that we can pass to the $() function." The documentation for the jQuery constructor says "calling the jQuery() method with no arguments returns an empty jQuery set."

With this regression, the behavior of .find() and $() are now inconsistent. Calling .find() should return an empty jQuery set instead of throwing an error.

While it's true that the behavior of .find() in this case was loosely documented, it's likely that there are plugins or other code depending on this behavior. Since this throws an error now it will very likely break other, seemingly unrelated elements on the page. This may prevent people from being able to upgrade.

comment:3 Changed 8 years ago by Akanksha

My code is giving error TypeError: $ is undefined at line in js file $.each(feedData, function(entryIndex, entry){

Thanks appointmentagent.com

Note: See TracTickets for help on using tickets.