JQuery after will not insert the <body> element
3 answers
This is due to the way jQuery HTML insertion functions work with before()and after(). IIRC, they create a temporary item and set up the innerHTMLnewly created item before moving items to where they should be. Since a tag <body>can only be a child of an element <html>, major browsers remove it from the source. However, when you add elements to an element <html>, in any case, the new element should be implied <body>.
, DOM createElement() append() html():
var newbody = document.createElement("body");
$(newbody).html("<div>hello</div>");
$("body").remove();
$("html").append(newbody);
: http://jsfiddle.net/3dSN4/ (, )
, , body. , , .
+5