1document.addEventListener("keypress", function onEvent(event) {
2 if (event.key === "ArrowLeft") {
3 // Move Left
4 }
5 else if (event.key === "Enter") {
6 // Open Menu...
7 }
8});
9
1The keypress event has been deprecated,
2you should look to use beforeinput : https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/beforeinput_event
3or keydown : https://developer.mozilla.org/en-US/docs/Web/API/Document/keydown_event
4instead.
5
6(And don't forget to like answers that help you !)
1// Create your variable and asssign it to your ID or Class in the document using document.querySelector.
2let name = document.querySelector('#exampleInputEmail1');
3
4// Now use your variable and add an event listener to it plus your keypress, event and styling
5name.addEventListener("keypress", (event) => {
6 name.style.border = "3px solid #28a745";
7});