In a default behavior, the textarea "press" enter will become new line, but I don't want to having a new line, I want the user press shift+enter, instead. How can I do so? or... ... can I return the textarea enter event before it actually fire to the text area?
\n is the linefeed character literal (ASCII 10) in a Javascript string. <br/> is a line break in HTML. Many other elements, eg <p> , <div> , etc also render line breaks unless overridden with some styles.
To detect shift+enter and generate a new line in text area with JavaScript, we can check for shift and enter key presses in the event object. textArea. onKeyPress = (e) => { if (e. keyCode === 13 && e.
To start a new line of text or add spacing between lines or paragraphs of text in a worksheet cell, press Alt+Enter to insert a line break.
$("textarea").keydown(function(e){
// Enter was pressed without shift key
if (e.key == 'Enter' && !e.shiftKey)
{
// prevent default behavior
e.preventDefault();
}
});
Try the jsFiddle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With