[jQuery] Undefined selector returning the document
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?