Why doesn't fire event fire after mouseDown event on the same element?

I have a mouseDown event and a click event on one element. When I click on it, the mouseDown event fires (ie, the "Mouse Pressed on P" warnings), but there is no click event. However, if I comment out the mouseDown alert statement, the click event will show its alert. Why is this? http://jsfiddle.net/A8vhq/

+3


source to share


3 answers


This is because the click never occurs when the alert box appears, it interrupts the mouseup event on the element, interrupting the mouseclick.



use console.log('message')

to test the code instead alert

.

+6


source


alert

Use instead console.log

and it will work.

Live demo: http://jsfiddle.net/A8vhq/1/




Btw, I changed the code a bit:

$('p').on('mousedown', function (e) {
    console.log('Mouse pressed on ' + e.target.nodeName);
});

$('p').on('click', function (e) {
    console.log(e.target.nodeName + ' clicked');
});

      

0


source


Just replace alert

with console.log

or any other non-modal method .

0


source







All Articles