title: jQuery: $.trim() spaces between words in input.val()
body: <p>I've seen some similar questions to mine here, but they don't really answer me...</p>
  
  <p>So I'm doing this: (Inside the document ready function)</p>
  
  <pre><code>$("#dest").focusin(function() {
      $("#dest").val($.trim($("#dest").val()));
  });
  </code></pre>
  
  <p>The ideia is when the user focus on a <code>input</code> called <code>#dest</code> trim all the space characters on it (previously added using focusout for visual comfort).</p>
  
  <p>Right now, nothing is happening. :(</p>
  
  <p>Hope someone can help me a bit here.</p>
  
  <p>Thanks!</p>
  
  <hr>
  
  <p><strong>Is this a computer related problem?</strong>
  I've tested all the code provided by commenters and none works. I'm using Firefox and Safari under OSX (Snow Leopard) 10.6.8 and also Safari under 10.8.2 (Lion) and I got the same results... OSX problem? -- <strong>Everything is ok, check my last edit!</strong></p>
  
  <hr>
  
  <p><strong>Final Edit and Solution thanks to Phil Klein</strong></p>
  
  <p>My problem was using incorrectly jQuery's <code>trim()</code> function... According to the <code>trim()</code> <a href="http://api.jquery.com/jQuery.trim/" rel="nofollow noreferrer">documentation</a> it does the following:</p>
  
  <blockquote>
    <p>The $.trim() function removes all newlines, spaces (including
    non-breaking spaces), and tabs from the beginning and end of the
    supplied string. If these whitespace characters occur in the middle of
    the string, they are preserved.</p>
  </blockquote>
  
  <p>Yesterday I didn't read the last part where it says <code>from the beginning and end of the supplied string</code> -- Sorry everyone. :(</p>
  
  <p>Lucky and after the drawing above, @Phil Klein understood my mistake and helped me with a solution:</p>
  
  <pre><code>$(function() {
      $("#dest").on("focus", function() {
          var dest = $(this);
          dest.val(dest.val().split(" ").join("")); 
      });
  });
  </code></pre>
  
  <p>You can <a href="https://stackoverflow.com/questions/8570641/jquery-trim-and-input-val/8570679#8570679">read more about the solution and see an example here</a>.</p>
  
  <p>Thanks to @Phil Klein and also everyone who helped me on this one ;)</p>