Skip to main content

Bug Tracker

Side navigation

#1807 closed bug (wontfix)

Opened October 15, 2007 06:28PM UTC

Closed March 18, 2009 04:02AM UTC

jQuery(undefined) returns document

Reported by: gyphie Owned by: aflesler
Priority: major Milestone: 1.2.2
Component: core Version: 1.2.1
Keywords: Cc:
Blocked by: Blocking:
Description

When calling jQuery() or $() with an undefined value parameter ''document'' is returned instead of an ''empty set''.

var undefined_something;
jQuery(undefined_something).click(function() { alert("You clicked me!");});

The above sample results in an onclick event bound to document. Any click anywhere displays an alert box.

Expected behavior is that an empty set is returned and .click does not bind any events.

I've attached a patch to jQuery-1.2.1.js that corrects the issue while still allowing jQuery() to return document.

(p.s. This is my first bug report, pardon me if I selected the wrong options from the drop down boxes)

Attachments (1)
  • jQuery.patch.txt (1.1 KB) - added by gyphie October 15, 2007 06:29PM UTC.

    Unified diff for patching the bug.

Change History (6)

Changed November 18, 2007 03:43AM UTC by davidserduke comment:1

owner: → davidserduke
status: newassigned

While I see your point and tend to agree with you, historically both jQuery() and jQuery(undefined) have returned the document object so arguable that is the expected behavior at this point. So I'd probably close this bug on the basis that it isn't worth the fix which could have significant effects.

I'll see if I can get another opinion first though.

Changed November 18, 2007 05:14PM UTC by brandon comment:2

I'm leaning towards fixing this but we might need to wait until another bump in the minor version.

Changed November 30, 2007 01:58AM UTC by davidserduke comment:3

owner: davidserduke
status: assignednew

Changed January 07, 2009 04:33AM UTC by dmethvin comment:4

owner: → aflesler

I would like to see this fixed, but as a workaround I have been using this:

$(whatever || [])

Which gives an empty jQuery object.

Changed January 31, 2009 04:44PM UTC by dmethvin comment:5

Make that

$(whatever || []) 

Bug #3695 is a duplicate of this bug.

Changed March 18, 2009 04:02AM UTC by brandon comment:6

resolution: → wontfix
status: newclosed

This is the current expected behavior.