How to re-fire (or later fire) the mousedown event in jQuery?

Recently, one question has arisen: in the handler, mousedownI use .preventDefaultin the event to prevent the selection of text when dragging:

$(document).bind('mousedown', function(event){
    event.preventDefault();
});

So far so good.

Then, by clicking the mouse button, I want to wait for the event to happen longclick( http://github.com/pisi/Longclick ) and the handler longclickto somehow resume the original event mousedownand start selecting the text, as if the default event was not prevented .

Is there a way to late trigger an otherwise native mouse event?

Is it .triggercapable of somehow accepting an existing (stored) event object? For example, something like this:

var originalEvent;

$(document)
    .bind('mousedown', function(event){
        event.preventDefault();
        originalEvent= event;
    })
    .bind('longclick', function(event){
        $(event.target).trigger(originalEvent)
    })

- .

, !

+3
1

trigger jQuery ( , jQuery, ), , this, . DOM 2, dispatchEvent, , fireEvent, , .

+1

Source: https://habr.com/ru/post/1780938/


All Articles