Does using event.preventDefault() in "mousedown" prevent "click" or "mouseup" event in jquery?

Madhu picture Madhu · Feb 20, 2014 · Viewed 22k times · Source

I am new to jquery and i have a doubt whether using events.preventDefault() in the mousedown or mouseup events does prevent the click or dblclick event?

Please provide me a clarification or a sample.

Thanks in advance. Madhu

Answer

Felix picture Felix · Feb 20, 2014

Neither of mouseup or mousedown prevent the default click event.

Fiddle Demo

You need to use click():

$('#test').on('click', function(e) {
    e.preventDefault();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<div onclick="alert('Clicked')" id="test">Click Here</div>

Fiddle Demo