Madhu
Madhu

Reputation: 2551

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

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

Upvotes: 22

Views: 35473

Answers (2)

Felix
Felix

Reputation: 38112

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

Upvotes: 12

Quinn
Quinn

Reputation: 458

It does not prevent the event itself, but the action that is triggered by the event.

A simple example would be clicking on an anchor link. The default action of the click event is to take the browser to a new URL. In this case, it won't happen.

Upvotes: 3

Related Questions