Search notes:

DOM example: documentElement

document.documentElement returns a document's root element (in no-quirks mode, that is). Thus, in a HTML document, it returns its <html> element (even if the document does not have an explicit <html> element).
<!DOCTYPE html>
<html>
<head>
  <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
  <title>document.documentElement</title>

<script type="text/JavaScript">

function main() { try {
   var rootElement = document.documentElement;

   var table = document.getElementById('table');

   var rows = table.rows;

   for (var r=0; r<rows.length; r++) {

     var cells = rows[r].cells;

     var key  = cells[0].innerHTML;
     cells[0].innerHTML = key + ':';


     cells[1].innerHTML = rootElement[key];
   }


 } catch(e) {alert (e);}
}

</script>

</head>
<body onload='main();'>
  
  <code>document.documentElement</code> gets the root element.

  <table id='table'>
    <tr><td>tagName</td><td></td></tr>
    <tr><td>nodeName</td><td></td></tr>
    <tr><td>localName</td><td></td></tr>
  </table>

</body>
</html>
Github repository about-Document-Object-Model, path: /Node/Document/documentElement.html

See also

The document object.
document.body returns the <body> element.
SVG/JavaScript example: access-root-element
DOM examples

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1745016754, '3.135.198.159', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/web/DOM/examples/Node/Document/documentElement(97): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78