An event bubbles by default unless you use e.stopPropagation()
:
document.getElementsByTagName('textarea')[0].addEventListener('keyup', function(e) {
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
e.preventDefault();
return;
}
});
document.getElementsByTagName('div')[0].addEventListener('keyup', function(e) {
console.log('Bubbled');
});
<div>
<textarea>
</textarea>
</div>
Now if I understand you correctly, you want to prevent the default behavior on the element which has fired the event, but not on the parent elements.
In your particular use case, I guess you want to preserve the scroll behavior of the up and down arrows, but I'm afraid it's not possible for two reasons:
So you have to implement a scroll behavior yourself (which will result in a strange behavior for most users, in my opinion).