Preserving whitespace in jQuery .val()

Found this article today which had a method for preserving white space in jQuery’s .val() function.

$.valHooks.textarea = {
  get: function( elem ) {
      return elem.value.replace( /\r?\n/g, "\r\n" );
}};

Leave a Reply