tags:

views:

770

answers:

4

I used $(document).html(), but that threw an error... is there a way to get everything?

+4  A: 

You could try:

$("html").html();

If you want to also capture the hmtl tags you could concatenate them to the html like this:

function getPageHTML() {
  return "<html>" + $("html").html() + "</html>";
}
Jimmie R. Houts
Thanks!! That worked perfectly!!
Justin Lee
A: 

$("html").html() would get everything but the outer most html tags.

Max Schmeling
+2  A: 

Use:

document.body.innerHTML
Diodeus
+6  A: 

Don't forget the <html> tag can have attributes too. If you want the whole document this should work.

 var getEverything = function () {

   var htmlStartTag = function () {
      var attrs = $('html')[0].attributes;  
      var result = '<html';
      $.each(attrs, function() { 
         result += ' ' + this.name + '="' + this.value + '"';
      });                                               
      result += '>';
      return result;
   }    

   return htmlStartTag() + $('html').html() + '</html>';
 }
Patrick McElhaney
+1 for including the html tag attributes
Jimmie R. Houts