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

偶尔善良 提交于 2019-11-30 18:27:20

Neither of mouseup or mousedown prevent the default click event.

Fiddle Demo

You need to use click():

$('.test').on('click', function(e) {
    e.preventDefault();
});

Fiddle Demo

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!