I need to detect mouseup
event after mousedown
on the document.
I have tried to add an event listener to document
and document.documentElement
with no success.
I need possibly a cross platform solution without jquery.
Notes: problem appears on not all browsers using alert()
.
http://jsfiddle.net/0f7vrzh7/8/
document.documentElement.addEventListener('mousedown', function(){
alert('mousedown');
});
document.documentElement.addEventListener('mouseup', function(e){
alert('mouseup')
});
The mouseup event is fired at an Element when a button on a pointing device (such as a mouse or trackpad) is released while the pointer is located inside it. mouseup events are the counterpoint to mousedown events.
MouseDown occurs when the user presses the mouse button; MouseUp occurs when the user releases the mouse button.
jQuery mouseup() Method The mouseup event occurs when the left mouse button is released over the selected element. The mouseup() method triggers the mouseup event, or attaches a function to run when a mouseup event occurs. Tip: This method is often used together with the mousedown() method.
In certain browsers the first alert would stop the second event. It works even with alert
in IE11 for example. In the browsers where you experience this issue the alert box blocks the UI before the mouseup
event is processed or propagated to the element you have the event handler attached to. Change to console.log()
statements in your event handlers and the events are fired as you expect them to. Updated fiddle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With