0

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 :)

  • 2
    Why not use the `click` event instead of `mousedown`? – Robby Cornelissen Apr 21 '22 at 11:01
  • And if you posted a [mcve] along with expected behaviour we could help you better – mplungjan Apr 21 '22 at 11:02
  • Are you trying to handle event on mouse hover? if yes then with alert() the preventDefault will not work definitely because the alert() will focus your window and then again your mousedown event will call multipletime –  Apr 21 '22 at 11:11

2 Answers2

0

Neither of mouseup or mousedown prevent the default click event.

See this answer for more details.

ScrapCode
  • 2,109
  • 5
  • 24
  • 44
  • On Click event, I am opening one dropdown for filter. but at certain condition I wanted to prevent that click event call. So if there is any way to prevent click event call, That will also help me. – Swapnali Hadawale Apr 21 '22 at 11:06
  • _"See this [answer](https://stackoverflow.com/a/21900619/3048967)..."_ - So there's a question that has an answer that also solves this question. So why don't you vote to close as dupe of that referenced question then? – Andreas Apr 21 '22 at 11:06
0

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

Liki Crus
  • 1,901
  • 5
  • 16
  • 27
TechnoDeveloper
  • 50
  • 1
  • 10