If doctype is <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
// do something
else
// do something
How to?
Thanks.
Right, I'm back after testing this in IE, Chrome, Firefox and Opera. IE will give you the full doctype with the following piece of code:
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 incorrect, as Chrome, Firefox and Opera return null for nodeValue. Since none of them support outerHTML, I can't think of a way to get the full doctype, but you can get 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, that doesn't work in IE, but it wouldn't be too difficult to parse those out. You can use an if statement to check that nodeValue is not null and fall back to checking systemId or publicId.
Script used to run the tests: http://jsfiddle.net/Cwb8q/
You could use the jQuery.support object to check for specific browser features (e.g. BoxModel) and working against them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With