Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mouseup event on document.documentElement does not fire with alert

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')
});
like image 898
GibboK Avatar asked May 05 '15 06:05

GibboK


People also ask

What is a Mouseup event?

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.

What is Mouseup and Mousedown?

MouseDown occurs when the user presses the mouse button; MouseUp occurs when the user releases the mouse button.

What is Mouseup method?

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.


1 Answers

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.

like image 175
Konstantin Dinev Avatar answered Oct 14 '22 21:10

Konstantin Dinev