JQuery check doctype
If doctype is <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> // do something else // do something How?
Thank.
That's right, I came back after testing this in IE, Chrome, Firefox and Opera. IE will provide you with a complete doctype with the following code snippet:
var doctype = document.documentElement.previousSibling.nodeValue; // -> DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" Unfortunately, this is probably not true, as Chrome, Firefox, and Opera return null for nodeValue . Since none of them supports outerHTML , I can't think of a way to get the full doctype, but you can get the individual parts:
var doctype = document.documentElement.previousSibling; console.log(doctype.systemId) // -> http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd console.log(doctype.publicId) // -> -//W3C//DTD XHTML 1.0 Strict//EN However, this does not work in IE, but it would not be too difficult to parse them. You can use the if to verify that nodeValue not null , and return to checking systemId or publicId .
Script is used to run tests: http://jsfiddle.net/Cwb8q/
You can use the jQuery.support object to test and work with certain browser functions (e.g. BoxModel).
Try using the attribute "this.document.doctype" If it is not declared, the result will be zero, otherwise the result will be an object with doctype.
document.doctype and document.firstChild both seem to return doctype, although I don't know how widely supported they are.
You can try:
var doc = $ ("DOCTYPE");