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 msg = document.getDocumentById('#message');
2
3msg.addEventListener("keydown", (event) => {
4 // handle keydown
5});
6
7msg.addEventListener("keypress", (event) => {
8 // handle keypress
9});
10
11msg.addEventListener("keyup", (event) => {
12 // handle keyup
13});
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});