Reputation: 119
I want to detect when the enter key is pressed in a textarea
I want it to work on mobile too
When the textarea is focused, and they press enter on the onscreen keyboard, it still detects and when they are using an external keyboard or computer keyboard it also detects.
Upvotes: 6
Views: 1674
Reputation: 89344
You can directly check the keyCode
.
document.querySelector('textarea').addEventListener('keypress', function(e){
if(e.keyCode === 13) alert('Enter');
});
Upvotes: 3