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 !)
1let b = document.getElementById("body"); //making var for body
2b.addEventListener("keydown", (evt) => {//when this happens
3 console.log(evt.keyCode); //log keycode
4});
5
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});