title: jQuery() vs jQuery.parseHtml() whitespace syntax error
body: <p>I have a line of javascript that is causing a syntax error in jQuery:</p>
  
  <pre><code>$(document).find('.Container').replaceWith($(data).find('.Content'));
  </code></pre>
  
  <p>The code itself if fairly innocuous all it does is takes the response data from an ajax call, targets some inner content and then substitutes this content for that of a container div element. However when the response data has leading space it causes a syntax error within jQuery.</p>
  
  <p>For example the following stripped back reponse data is fine:</p>
  
  <pre><code>$("&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;")
  </code></pre>
  
  <p>However the same response with a preceding space is not:</p>
  
  <pre><code>$(" &lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;")
  </code></pre>
  
  <p>And gives the following error message:</p>
  
  <pre><code>Syntax error, unrecognized expression: &lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <p>I am guessing it may have something to do with the way that jQuery is testing the parameters of jQuery function (which $() is an alias for) to differentiate between the different overloads.</p>
  
  <p>I also noticed that the jQuery function <code>$.parseHTML()</code> seems to cope with leading spaces as the following line of code is fine:</p>
  
  <pre><code>$.parseHTML(" &lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;")
  </code></pre>
  
  <p>Does anyone know if this is a bug with jQuery? Or is it simply a case that the <code>jQuery()</code> function requires that it should not have leading spaces.</p>
  
  <p>Btw the version of jQuery is 1.9.1</p>
  
  <p>UPDATE <strong>**************************************************************************************</strong></p>
  
  <p>Thanks to a tip off from a colleague I've found out that this is an actual bug (although it wasn't initially accepted as one by the jQuery team - <a href="http://bugs.jquery.com/ticket/13223" rel="nofollow">read the comments</a>). It looks like it will be/has been 'fixed' in jQuery 1.10/2.0.</p>