I think that is my fault; it was a patch I submitted way back at the beginning of last year. But you're right, $(undefined) shouldn't select the document, only $() with no arguments at all should. Want to file a ticket on it?
The offending code is at the beginning of jQuery.fn.prototype: // Make sure that a selection was provided selector = selector || document; That really should be: // Select document object for $() if( ! arguments.length ) selector = document; -Mike > From: Jake > > I am having a problem with jQuery (2.1.1). > > I have a set of variables defined and depending on > circumstances some may be undefined. > > A simple stupid example: > var element_id; > var the_element = jQuery(element); > the_element.click(function () { alert('Hello World'); }); > > The result of this is that any click anywhere produces the > "Hello World" alert box. The expected behavior was that no > click event would be bound since element_id was undefined and > so no matching element could be found. Not binding document.click. > > I suppose jQuery behaves this way is so calling jQuery() > without any parameters returns "document" and you can work on > it in the short concise jQuery way. > > But doesn't this seem like incorrect behavior?