Detect when user press ENTER

6

I have a jQuery code that detects when the ENTER key is pressed, but the event is also called when I use Shift + ENTER , for example.

How do I detect only ENTER ? The intent is to send the form only when the ENTER key is pressed, leaving Shift + Enter for line break.

$(document).on('keyup', '.comment-textarea', function(event) {   
    if (event.which == 13) {
        console.log('ENTER');
    }
});
    
asked by anonymous 23.11.2015 / 22:59

1 answer

8

Do this, make sure the shift is tight.

$(document).on('keyup', '.comment-textarea', function(event) {   
    if (event.which == 13) {
         if(event.shiftKey){
             console.log('Quebra de linha');
         }else{
             console.log('ENTER');
        }
    }
});
    
23.11.2015 / 23:06