MDN self-hosted library · e01.org

Anatomy of the DOM

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>Document</title>
  </head>
  <body>
    <h1>Hello, world!</h1>
    <p>This is a paragraph.</p>
  </body>
</html>
html
<p class="note" id="intro">This is a paragraph.</p>
html
<div>Hello, <span>world</span>!</div>
html
<text>Some text</text>
<style><![CDATA[h1 { color: red; }]]></style>
html
<!-- This is a comment -->
html
<p class="note" id="intro">This is a paragraph.</p>
js
if (a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_PRECEDING) {
  // a precedes b
}