Following code is an example of text placed into a textarea from a database.
Try this:
var $input = $('#inputPane');
var $container = $('').html( $input.val() );
$('*', $container).text( function(i,txt) {
return $.trim( txt );
});
$input.val( $container.html() );
It turns the content of the textarea
into elements, walks through them and trims the content, then inserts the resulting HTML back into the textarea
.
EDIT: Modified to use .val()
instead of .text()
as noted by @bobince