2.1 document Node Overview
<!DOCtyPE html>
<html lang="en">
<body>
<script>
// logs function HTMLDocument9) { [native code] }
console.log(window.document.constructor);
// logs 9, which is a numeric key mapping to DOCUMENT_NODE
console.log(window.document.nodeType);
</script>
</body>
</html>
cf)
2.2. HTMLDocument Properties and Methos (Including Inherited)
<!DOCTYPE html>
<html lang="en">
<body>
<script>
// document own properties
console.log(Object.keys(document).sort());
// document own properties and inherited properties
var documentPropertiesIncludedInherited = [];
for (var p in document) {
documentPropertiesIncludedInherited.push(p);
}
console.log(documentPropertiesIncludeInherited.sort());
// document inherited properties only
var documentPropertiesOnlyInherited = [];
for (var p in document) {
if (!document.hasOwnProperty(p)) {
documentPropertiesOnlyInherited.push(p);
}
}
console.log(documentPropertiesOnlyInherited.sort());
</script>
</body>
</html>
2.3 Getting General HTML Document Information (title, url, referrer, lastModified, and compatMode)
<!DOCTYPE html>
<html lang="en">
<body>
<script>
var d = document;
console.log('title = ' + d.title);
console.log('url = ' + d.URL);
console.log('referrer =', + d.referrer);
console.log('lastModified = ' + d.lastModified);
// lofs either BackCompat (Quirks Mode) or CSS1Compat (Strict Mode)
console.log('compatibility mode = ' + d.compatMode);
</script>
</body>
</html>
2.4 document Child Nodes
<!DOCTYPE html> <html lang="en">...</html><!DOCTYPE html>
<html lang="en">
<body>
<script>
var d = document;
// logs 10, which is a numeric key mapping to DOCUMENT_TYPE_NODE
console.log(d.childNodes[0].nodeType);
// logs 1, which is a numeric key mapping to ELEMENT_TYPE_NODE
console.log(d.childNodes[1]nodeType);
</script>
</body>
</html>
window.document는 HTMLDocument 생성자로부터 만들어졌으며, DOM interface의 시작점임.2.5 Document Provides Shortcuts to <!DOCTYPE>, <html lang="ko">, <head>, and, <body>
<!DOCTYPE html>
<html lang="en">
<body>
<script>
var d = document;
// logs documentType {nodeType=10, ownerDocument=document, ...}
console.log(d.doctype);
// logs 1, <html lang="ko">
console.log(d.documentElement);
// logs <head>
console.log(d.head);
// logs <body>
console.log(d.body);
</script>
</body>
</html>
window.document는 HTMLDocument 생성자로부터 만들어졌으며, DOM interface의 시작점2.6 Using document.implementation.hasFeature() to Detect DOM Specifications/Features
표1. hasFeature() 매개변수 값
| 특징 | 지원되는 버전 |
|---|---|
| Core | 1.0, 2.0, 3.0 |
| XML | 1.0, 2.0, 3.0 |
| HTML | 1.0, 2.0 |
| Views | 2.0 |
| StyleSheets | 2.0 |
| CSS | 2.0 |
| CSS2 | 2.0 |
| Events | 2.0, 3.0 |
| UIEvents | 2.0, 3.0 |
| MouseEvents | 2.0, 3.0 |
| MutationEvents | 2.0, 3.0 |
| HTMLEvents | 2.0 |
| Range | 2.0 |
| Traversal | 2.0 |
| LS(loading and saving between files and DOM trees synchronously) | 3.0 |
| LS-Async(loading and saving between files and DOM trees asynchronously) | 3.0 |
| validation | 3.0 |
2.7 Getting a Reference to the Focus / Active Node in the Document