Window Document object
- Vorige pagina defaultStatus
- Volgende pagina focus()
- Ga naar het vorige niveau Window Object
Document object
Wanneer het HTML-document wordt geladen in een webbrowser, wordt het eenDocumentobject.
Documentobjectis de rootnode van het HTML-document.
DocumentobjectisVensterobjectvan de eigenschappen.
Toegang via de volgende manierenDocumentobject
:
window.document
of alleen document
Voorbeeld
let url = window.document.URL;
let url = document.URL;
Documentobject eigenschappen en methoden
De volgende eigenschappen en methoden zijn beschikbaar voor HTML-documenten:
Eigenschap / Methode | Beschrijving |
---|---|
activeElement | Terug naar het element dat momenteel de focus heeft in het document. |
addEventListener() | Attaches an event handler to the document. |
adoptNode() | Adopts a node from another document. |
anchors | Verouderd. |
applets | Verouderd. |
baseURI | Returns the absolute base URI of the document. |
body | Sets or returns the body (the <body> element) of the document. |
charset | Verouderd. |
characterSet | Returns the character encoding of the document. |
close() | Closes the output stream previously opened with document.open(). |
cookie | Returns the name/value pairs of all cookies in the document. |
createAttribute() | Creates an attribute node. |
createComment() | Creates a Comment node with specified text. |
createDocumentFragment() | Creates an empty DocumentFragment node. |
createElement() | Creates an element node. |
createEvent() | Creates a new event. |
createTextNode() | Creates a text node. |
defaultView | Returns the window object associated with the document, or null if none is available. |
designMode | Controls whether the entire document should be editable. |
doctype | Returns the document type declaration associated with the document. |
documentElement | Returns the Document element (the <html> element) of the document. |
documentMode | Verouderd. |
documentURI | Sets or returns the location of the document. |
domain | Returns the domain name of the server that loaded the document. |
domConfig | Verouderd. |
embeds | Returns the collection of all <embed> elements in the document. |
execCommand() | Verouderd. |
forms | Returns the collection of all <form> elements in the document. |
getElementById() | Returns the element with the specified ID attribute value. |
getElementsByClassName() | Returns all elements that have the specified class name. HTMLCollection. |
getElementsByName() | Returns the active elements that have the specified name. NodeList. |
getElementsByTagName() | Returns all elements that have the specified tag name. HTMLCollection. |
hasFocus() | Returns a boolean value indicating whether the document has focus. |
head | Returns the <head> element of the document. |
images | Returns the collection of all <img> elements in the document. |
implementation | Geef het DOMImplementation-object dat dit document afhandelt terug. |
importNode() | Importeer knooppunten van een ander document. |
inputEncoding | Verouderd. |
lastModified | Geef de datum en tijd van de laatste wijziging van het document terug. |
links | Geef de verzameling van <a> en <area>-elementen terug die eigenschappen hebben met href in het document. |
normalize() | Verwijder lege tekstknooppunten en verbind nabijgelegen knooppunten. |
normalizeDocument() | Verouderd. |
open() | Open de HTML-uitvoerstream om de output van document.write() op te slaan. |
querySelector() | Geef het eerste element terug dat overeenkomt met de opgegeven CSS-selectors in het document. |
querySelectorAll() | Geef een statische NodeList terug die alle elementen bevat die overeenkomen met de opgegeven CSS-selectors in het document. |
readyState | Geef de status van het (laden) document terug. |
referrer | Geef de URL van het document terug dat het huidige document heeft geladen. |
removeEventListener() | Verwijder eventhandler uit het document (reeds gebruikt addEventListener() methode aangevuld). |
renameNode() | Verouderd. |
scripts | Geef de verzameling van <script>-elementen in het document terug. |
strictErrorChecking | Verouderd. |
title | Stel de titel van het document in of geef hem terug. |
URL | Geef de volledige URL van het HTML-document terug. |
write() | Schrijf HTML-uitingen of JavaScript-code in het document. |
writeln() | Gelijk aan write(), maar voegt een nieuwe regel toe achter elke regel. |
Beschrijving van het Document-object
Het HTMLDocument-interface breidt het DOM Document-interface uit en definieert HTML-gebruikte eigenschappen en methoden.
Vele eigenschappen en methoden zijn HTMLCollection-objecten (ze zijn in feite leesbare arrays die met naam of index kunnen worden bereikt), waarin verwijzingen naar ankers, formulieren, links en andere script-elementen worden opgeslagen.
Deze verzamelattributen komen allemaal voort uit het 0-niveau DOM. Ze zijn reeds Document.getElementsByTagName() is vervangen, maar wordt nog vaak gebruikt omdat het gemakkelijk is.
write() methodeHet is de moeite waard op te merken dat het bij het laden en parseren van documenten een script toestaat om dynamisch gegenereerde inhoud in het document in te voegen.
Let op, in het 1e niveau DOM definieert HTMLDocument een genaamd getElementById() zeer nuttige methoden. In het 2e niveau DOM is deze methode verplaatst naar het Document-interface, en wordt het nu geërfd door HTMLDocument in plaats van door het zelf gedefinieerd te zijn.
- Vorige pagina defaultStatus
- Volgende pagina focus()
- Ga naar het vorige niveau Window Object