0

VS code crosses out event.key. I think it's deprecated. I want the code below to run when I press enter. What should I do VS code crosses out event.key. I think it's deprecated. I want the code below to run when I press enter. What should I do

  //js code    
  document.querySelector("#addNewTaskBtn").addEventListener("click",newTask);    
  document.querySelector("#addNewTaskBtn").addEventListener("keypress",()=>{    
     // Problem is here
    if(event.key=="Enter"){
     //vs code crosses out event.key. I think it's deprecated. I want the code below to 
     //run  whenI press enter. What should I do
         document.getElementById("addNewTaskBtn");
          }
    });

1 Answers1

1

Replacement for deprecated `keypress` DOM event

https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code

Keydown is likely your better choice instead of keypress, and KeyboardEvent.code is likely your better choice instead of event.key.