Reputation: 2599
I have a textarea HTML5 input with cols=120
set. When a user types a long string on it, the string may get wrapped into several lines, to fit the specified columns.
However, when I try to retrieve the text value of the element, the long string is not with any kind of line breaks associated.
Is there a way to get a string representation from the textarea which includes linebreaks exactly where the long string got wrapped, so that it goes the exact same way it was displayed into the screen?
Upvotes: 1
Views: 228
Reputation: 2599
Seems promising.Will test it here.
finding "line-breaks" in textarea that is word-wrapping ARABIC text
Thanks SO Related answers!
Upvotes: 0
Reputation: 47791
You can use <textarea wrap="hard" ...
to submit a form including line breaks as it appears to the user.
Upvotes: 1
Reputation:
Use .val() to get value of textarea and use $.trim() to empty spaces.
$(document).ready(function () {
var val = $.trim($("textarea").val());
if (val != "") {1
$('div').append('<pre>'+val+'</pre>');
}
});
Demo : jsfiddle
Upvotes: 0