Skip to content

Instantly share code, notes, and snippets.

@tomgrohl
Created August 24, 2012 23:06
Show Gist options
  • Save tomgrohl/3456919 to your computer and use it in GitHub Desktop.
Save tomgrohl/3456919 to your computer and use it in GitHub Desktop.
A simple function for getting if a document is XHTML+XML
function getContentType() {
var type = "text/html",
rXHTML_XML = /application\/xhtml\+xml/i,
element = $(document).find("meta[content][http-equiv='Content-Type']");
if( element.length ) {
content = element.attr("content");
if( rXHTML_XML.test( content ) ) {
type = "application/xhtml+xml";
}
}
return type;
}
function isXHTML() {
var node = document.doctype,
contentType = getContentType(),
rDOC = /TR\/xhtml(1|11)\/DTD\/xhtml(1|11)/i,
type = node.systemId;
if( contentType === "application/xhtml+xml" || ( type && contentType === "text/html" && rDOC.test( type ) ) ) {
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment