jQuery – Remove Extra Newline in Textarea


case:

createOnEnter: function(e) {
  if (e.keyCode == 13) {
    items.create(this.newAttributes());
    this.$("#create-item :input").val('');
    this.$("#create-item :input")[0].focus();
  };
},

solution:

Default behaviour of the Enter key in a textarea is to add a new line. To prevent this action occurring within the createOnEnter method, add e.preventDefault(); after matching the key press as the Enter key.

createOnEnter: function(e) {
          if (e.keyCode == 13) {
            e.preventDefault();
            items.create(this.newAttributes());
            $("#create-item :input").val('');
            $("#create-item :input")[0].focus();
          };
        }


source:
http://stackoverflow.com/questions/4299533/how-do-i-remove-the-extra-newline-in-textarea-after-clearing-it-with-jquery-val

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s