Reputation: 18861
jQuery("html").html() seems to retrieves most of it, except for the wrapping tag.
DOM is heavily modified, so original source is of not that much use.
EDIT: jQuery("").append(jQuery("html").clone()).html() almost works, except for doctype. Is there an easy way to get it?
EDIT 2: I need the doctype mostly to get proper quirk/almoststandards/standards mode. document.compatMode has half of it, is it enough?
Upvotes: 2
Views: 5485
Reputation: 29267
jQuery uses innerHTML
to get the HTML. You're not going to get the exact DOM state using this attribute. For example the content of input
values or the state of a select
box will not stay the same unless you properly modify it before calling innerHTML
.
What is this wrapping
tag you're talking about? For most of it, innerHTML should work fine.
For example, I use this code for the state of select
and input
boxes.
// it's defaultValue so we can use innerHTML
$("#divContentInside input").each(function () {
this.defaultValue = this.value;
});
// go through each select and replace
// it's selection so we can use innerHTML
$("#divContentInside select > option").each(function () {
if (this.selected) {
this.setAttribute("selected", true);
} else {
this.removeAttribute("selected");
}
});
I haven't found issues with state consistency of other elements, but there probably is.
Upvotes: 2
Reputation: 9117
http://brandonaaron.net/blog/2007/06/17/jquery-snippets-outerhtml/ outerHTML implementation for jquery.
Edit
Doing a quick search came in the document.doctype option, here is a full reference to it. Removed the old and now unnecessary text/code.
Upvotes: 0
Reputation: 25164
You can use standard DOM commands:
To get the innerHTML of the HTML tag
document.body.parentNode.innerHTML
To get the Doctype information
document.body.parentNode.previousSibling;
Upvotes: 2