-1

I am making a search bar that needs to detect if the enter key is pressed but I can't seem to find a working option. A little of my code:

<div class="searchbar">
    <input type="text" id="search" placeholder="Search">
  </div>

I tried

let input = document.querySelector('input');
input.addEventListener('keyup', (e) => {   
    if(e.keyCode === 13) {   
        console.log(e.target.value);   
    }   
})   

but keyCode is deprecated. Any advice?

Santrix
  • 1
  • 1
  • 1
    @Santrix refer [here](https://stackoverflow.com/questions/35394937/keyboardevent-keycode-deprecated-what-does-this-mean-in-practice) – Naren Murali Aug 20 '22 at 04:14

1 Answers1

-1

Instead of using e.keycode === 13 you can use e.key === 'Enter'

Elias
  • 122
  • 1
  • 3