<textarea style="height: 300px;" class="jqueryFindBody" cols="20" rows="2">
1
2
3
</textarea>
In the asp.net textbox above, if I replace its text with its own text, the line breaks get lost
$('.jqueryFindBody').text($('.jqueryFindBody').text());
I tried using html instead of text, but the line breaks are always lost. How do I preserve the line breaks?
How about using
.val()? http://api.jquery.com/valHere is a demo: http://jsfiddle.net/tXnaj/
Update
If you want to display the value of the
textareaelement in HTML then you’ll need to parse the endline characters into<br />tags. You can do this with a simple RegExp:This finds all the
\nand\rcharacters and replaces then with<br />tags.Here is a demo: http://jsfiddle.net/tXnaj/2/