const head = document.head;
const body = document.body;
if (head.compareDocumentPosition(body) & Node.DOCUMENT_POSITION_FOLLOWING) {
console.log("Well-formed document");
} else {
console.error("<head> is not before <body>");
}Node: compareDocumentPosition() method / notebook
Node: compareDocumentPosition() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.