This example demonstrates a simple technique for capturing mousemove and mouseup events that are initiated by a mousedown on an element of interest. The mousemove and mouseup listeners are registered on the window when the first mousedown event is received; thus, these listeners are automatically scoped to the initiating element (div
), while still being able to receive mouse events from anywhere in the current window. When the mouseup event is received, the window listeners are deleted.