Home

Published

- 1 min read

adding event on enter key keypress in javascript

img of adding event on enter key keypress in javascript

The solution for this is noted below

adding event on enter key keypress in javascript

Solution

   const elem = document.getElementById('input')

elem.addEventListener('keypress', (event) => {
	if (event.keyCode === 13) {
		// key code of the keybord key
		event.preventDefault()
		// your code to Run
	}
})

Try other methods by searching on the site. That is if this doesn’t work