Following code is an example of text placed into a textarea from a database.
jQuery.trim()
will remove leading and trailing whitespace from the entire string -- in this case, before the first and after the last
// assuming val is the textarea contents:
val = val.replace(/>\s*, '><').replace(/\s+$/, '');
DISCLAIMER: This was just quickly put together and may not cover every case.