javascriptjquerykeyboard-events

shift mouse click trigger


I can trigger click event on element selector using trigger

$('element selector').trigger('click')

Is it possible to trigger shift click. I mean shift + left mouse click.


Solution

  • try

    var shiftClick = jQuery.Event("click");
    shiftClick.shiftKey = true;
    
    $("element selector").click(function(event) {
        if (event.shiftKey) {
           alert("Shift key is pressed");
        }
        else {
           alert('No shift hey');
        }
    });
    
    $("element selector").trigger(shiftClick);
    

    JSFiddle