Aditya Singh
Aditya Singh

Reputation: 678

Keypress event in DOM

I just started learning DOM events, i was using keypress event to make some event happen when i press the enter key. It is working fine.

  document.addEventListener('keypress', function(event){

        if(event.keyCode === 13){
            console.log("enter was pressed");
        }
    });

But i read on MDN event reference that keypress event is deprecated.

MDN keypress reference

What is the reason of its depreciation and what is the new alternative of keypress event ?

Upvotes: 1

Views: 1372

Answers (1)

Mohit
Mohit

Reputation: 522

onkeyDown and onKeyUp are the alternativies for this. To maintain performance you can use Debounce for your logic.

Upvotes: 1

Related Questions