HTML5 adds many new semantic and functional tags. Although we can select them through document. getelementbyid and document. getelementsbytagname, a problem occurs when copying nodes. The innerhtml that should have appeared is a null string ......
<! Doctype HTML>
Therefore, we need to treat them differently when copying them, which is a prerequisite for how to identify them.
The following is a small test, which selects a scheme based on the log differences of different browsers:
Window. onload = function () {var test = document. createelement ("nav"); console. log (test. outerhtml); console. log (test. tagname); console. log (object. prototype. tostring. call (TEST ));}
The result is as follows:
ie9 log:
log: nav log: IE8 mode log of [object htmlunknownelement] ie9:
log: nav log: IE7 mode log of [object] ie9:
log: nav log: [object] IE8 log:
log: nav log: [object] IE7 log:
log: nav log: [object] ff12
nav [object htmlelement] chrome18
nav [object htmlelement] opera11
nav [object htmlelement] safari5
nav [object htmlelement]
Interestingly, if you have created a new tag that is not HTML5, The tostring of the element for opera, chrome, and FF are all [object htmlunknownelement]. But here we only talk about ie. IE is obviously regarded as inserting an XML element. Therefore, we only determine whether outerhtml (ff11 only supports outerhtml), and whether outerhtml uses"
Below is my framework replication NodeCode:
VaR DIV = document. createelement ("Div"); // cache parser to prevent repeated creation of function shimclonenode (outerhtml, tree) {tree. appendchild (DIV); Div. innerhtml = outerhtml; tree. removechild (DIV); Return Div. firstchild;} var unknowntag = "<? XML: namespace "function clonenode (node, dataandevents, deepdataandevents) {var bool //! Undefined = true; // This determination must be so long: Determine whether a new label can be cloned, determine whether it is an element node, and determine whether it is a new label if (! Support. clonehtml5 & node. outerhtml) {// delayed creation detection element var outerhtml = document. createelement (node. nodename ). outerhtml; bool = outerhtml. indexof (unknowntag )//! 0 = true;} var NEO =! Bool? Shimclonenode (node. outerhtml, document.doc umentelement): node. clonenode (true), SRC, Neos, I; // support. clonehtml5: Doc. createelement ("nav "). clonenode (true ). outerhtml! = "<: Nav> </: nav> ",//...... }
If you are interested, you can go to my GitHub for a transfer.