I know it\'s already discussed here, but there were no solution to get the whole document (including doctype).
$(document).html(); returns null
$(document).html();
null
document.documentElement.innerHTML
will return you all document markup as string
to get the whole doctype read this