0👍
✅
Use preventDefault
on the keydown
event instead of keyup
.
document.querySelector('textarea').addEventListener('keydown', e => {
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
e.preventDefault()
}
})
<textarea>Hello, World! Hello, World! Hello, World! Hello, World! </textarea>
Source:stackexchange.com