Home > Blockchain >  e.preventDefault() is not working with mousedown event?
e.preventDefault() is not working with mousedown event?

Time:04-21

I have written below code to prevent click event. Its working as expected with below code.

$(".k-grid-filter").on('mousedown', function (e) {
    var editRow = $(this).closest(".k-grid").find(".k-grid-edit-row");
    if (editRow.length > 0) {
        e.preventDefault();
        e.stopImmediatePropagation();
        alert(e.type);
    }
});

But I don't want to display alert pop-up. If I remove alert(), preventDefault() is not working.

$(".k-grid-filter").on('mousedown', function (e) {
        var editRow = $(this).closest(".k-grid").find(".k-grid-edit-row");
        if (editRow.length > 0) {
            e.preventDefault();
            e.stopImmediatePropagation();
        }
    });

Can anybody please help me to find is missing and what has to be done to make is work? Thanks in advance :)

CodePudding user response:

Neither of mouseup or mousedown prevent the default click event.

See this answer for more details.

CodePudding user response:

You can't use e.preventDefault() in mousedown and mouseup event because the function only works on click you have to select that part.

The mousedown event is fired at an Element when a pointing device button is pressed while the pointer is inside the element.

you can check reference of this link here

  • Related