Answer the question
In order to leave comments, you need to log in
Button event on elements?
How can I make it so that when an element, such as a DIV, is clicked, the keyboard up and down arrow press actions are triggered? For example, so that you can switch slides by clicking on the arrows (DIVs) and the actions of pressing the arrow buttons on the keyboard work?
Answer the question
In order to leave comments, you need to log in
With jQuery:
var keyUp = $.Event("keydown", { keyCode: 38 }),
keyDown = $.Event("keydown", { keyCode: 40 });
$(".div-up").trigger(keyUp);
$(".div-down").trigger(keyDown);
var evt = document.createEvent("Event");
evt.initEvent("keyup", true, true);
evt.keyCode = 38;
function a(e) {
alert(e.keyCode);
}
document.onkeyup = a;//функция при нажатии клавиши
document.dispatchEvent(evt);//срабатывание
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question