Bug Tracker

Modify

Ticket #1807 (closed bug: wontfix)

Opened 6 years ago

Last modified 4 years ago

jQuery(undefined) returns document

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

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

jQuery.patch.txt Download (1.1 KB) - added by gyphie 6 years ago.
Unified diff for patching the bug.

Change History

Changed 6 years ago by gyphie

Unified diff for patching the bug.

comment:1 Changed 6 years ago by davidserduke

  • Owner set to davidserduke
  • Status changed from new to assigned

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.

comment:2 Changed 6 years ago by brandon

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

comment:3 Changed 5 years ago by davidserduke

  • Owner davidserduke deleted
  • Status changed from assigned to new

comment:4 Changed 4 years ago by dmethvin

  • Owner set to aflesler

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

$(whatever
[])

Which gives an empty jQuery object.

comment:5 Changed 4 years ago by dmethvin

Make that

$(whatever || []) 

Bug #3695 is a duplicate of this bug.

comment:6 Changed 4 years ago by brandon

  • Status changed from new to closed
  • Resolution set to wontfix

This is the current expected behavior.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.