title: Why can't I put the HTML page returned by $.ajax in the jQuery wrapper?
body: <p>The HTML returned in the $.ajax success callback doesn't let me put it in a jQuery wrapper and apply standard jQuery methods to it. Why is this? For example, this alerts null:</p>
  
  <pre><code>dataType: "html",
  success: function(myHTML) {
     var $myHTML = $(myHTML);
     alert( $myHTML.html() ); // returns null
  }
  </code></pre>
  
  <p>My intention is to modify the myHTML using jQuery methods (this is why I need to put it in the jQuery wrapper), and then return the modified html (full, including <code>&lt;head&gt;</code>, scripts, etc.) as a string. But none of the jQuery methods I try work on $(myHTML). How come?</p>
  
  <p>A working version of the code is here: <a href="http://jsfiddle.net/supertrue/Uw5dc/" rel="nofollow">http://jsfiddle.net/supertrue/Uw5dc/</a></p>
  
  <pre><code>var getHTML = function ( url ){        
  
          $.ajax({
                    url: url,
                    dataType: "html",
                    success: function( myHTML ) {
  
                        // view the returned HTML
                        alert('Successfully grabbed this HTML: \n\n' + myHTML);
  
                        // the opening &lt;html&gt; tag is missing (no idea why)
                        myHTML.replace('&lt;head&gt;', '&lt;html&gt;&lt;head&gt;');
  
                        // put it in a jQuery wrapper
                        var $myHTML = $(myHTML);
  
                        // use jQuery to manipulate it
                        // $myHTML.find('script').remove(); // just an example
  
                        // then view the final html
                        alert('$myHTML.html(): \n\n' + $myHTML.html()); // doesn't work!
  
                        // that didn't work; try getting outerHTML
                        $myHTML = $('&lt;div&gt;&lt;/div&gt;').append(myHTML);
                        alert('$myHTML.html(): \n\n' + $myHTML.html()); // highly incomplete! missing scripts and &lt;head&gt;, &lt;body&gt; wrappers    
  
                    }
                });
  
       }
  </code></pre>