<p>I have a form that uses jQuery to submit an ajax post and it serializes the form that is sent up. The code looks like this:</p>

<pre><code>var form = $("form");
var action = form.attr("action");
var serializedForm = form.serialize();
$.post(action, serializedForm, function(data)
{
  ...
});
</code></pre>

<p>The problem here is that if a field has trailing white space, the serialize function will turn those spaces to plus (+) signs, when they should be stripped.</p>

<p>Is there a way to get the fields trimmed <strong>without</strong> doing the following:</p>

<pre><code>$("#name").val( jQuery.trim( $("#name") ) );
</code></pre>

Trim all
<input>
and
<textarea></textarea>
element values in the DOM:
```
```
$('input, textarea').each(function(){
    $(this).val(jQuery.trim($(this).val()));
});
```
```