So let's say (in IE8) that we have a document
.
Now normally we can assume that document.childNodes[0]
is the doctype. So
var doctype = document.childNodes[0]
Now how do we confirm rather then assume it is the doctype?
doctype.nodeType === Node.COMMENT_NODE;
doctype.tagName === "!"; // same as a comment
doctype.data.indexOf("DOCTYPE ") > -1; // same as any comment containing the word DOCTYPE.
doctype === document.doctype; // false, document.doctype is undefined in IE8
Apart from assumptions, how am I supposed to know whether a given node is a doctype?
For those of you unfamiliar with DOM4 take a look at DocumentType
The DOM-shim get's document.doctype
in IE8 by just returning document.childNodes[0]