How can I activate a "left" or "right" keyboard arrow push on click of a div.
So for example
$('.item').click(function(){
keyCode(37);
});
(I know that 37
is left)
You would go like
$('.item').click(function(){
$( document.body ).trigger({
type: 'keypress',
which: 37,
keyCode: 37
});
});
You can of course replace document.body
with any other node that has a keypress
or keydown
event bound to it.
Reference: .trigger()
From Definitive way to trigger keypress events with jQuery:
var e = jQuery.Event("keypress");
e.which = 37; // # Some key code value
$("div").trigger(e);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With