generate functionSun, 11 Dec 2022

detect enter key in any input that is in focus

// detect enter key press // to prevent defualt behavior add: event.preventDefault() document.getElementById('input').addEventListener('keypress', (event) => { if (event.keyCode === 13) { console.log('you just hit the enter key') } })

Javascript
Generate More

Questions about programming?Chat with your personal AI assistant