views:

115

answers:

1

The following bit of code breaks in the upgrade to jquery 1.4:

$().mousemove(
    function (e) {
    defaults.mouseX = e.pageX;
    defaults.mouseY = e.pageY;
    });
};

What appeared to be a reasonable fix was adding "html" as the selector, ex: $("html").

The fix works fine - except now when the user mouses off the page, it doesn't register the mouse position beyond the boundaries. When attempting to use the mouse position for a drag, for example, the amount of movement beyond the screen is really important. Anyone got any ideas?

Thanks in advance.

+6  A: 

Prior to 1.4, $() was a shorthand for $(document). With 1.4, it actually produces an empty set (which makes more sense but was irritatingly difficult before).

Just write $(document) when that's what you need, and all will be well...

Shog9
Thanks. Out of curiosity, when would you want a an empty set?
Matrym
@Matrym: one scenario involves using a jQuery object as a quick and dirty document fragment, building a set of nodes for later insertion (or alternately, marking nodes for later deletion) - it can be cleaner to start with an empty set and then add to it vs. special-casing the first addition. A more general case is to pass around jQuery objects instead of IDs or raw element references, with the empty set standing in for a null reference (null object pattern).
Shog9