Categories
JavaScript Answers

How to detect “shift+enter” and generate a new line in text area with JavaScript?

Spread the love

To detect "shift+enter" and generate a new line in text area with JavaScript, we check the keys pressed in the keyup event handler.

For instance, we write

if (event.keyCode === 13 && event.shiftKey) {
  console.log("Shift+Enter key Pressed");
}

to check if enter is pressed by checking if keyCode is 13.

And we check if shift key is pressed with shiftKey.

If both are true, then shift+enter is pressed.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *