HTML DOM Document Object
- Vorige pagina Window Scherm
- Volgende pagina HTML Element
Document object
Wanneer het HTML-document is geladen in een webbrowser, wordt het eenDocumentobject.
Documentobjectis de rootnode van het HTML-document.
DocumentobjectisVensterobjecteigenschappen.
Toegang via de volgende manierDocumentobject:
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:
Eigenschappen / Methoden | Beschrijving |
---|---|
all[] | Retourner une référence à tous les éléments HTML du document. |
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 (body element) of the document. |
charset | Verouderd. |
characterSet | Returns the character encoding of the document. |
close() | Closes the output stream opened previously 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 the 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 of the document (<html> element). |
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 verwerkt terug. |
importNode() | Importeer een knooppunt uit 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 in het document terug die de eigenschap href hebben. |
normalize() | Verwijder lege tekstknooppunten en koppel aanpalende knooppunten samen. |
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 gespecificeerde CSS-selectie in het document. |
querySelectorAll() | Geef een statische NodeList terug die alle elementen bevat die overeenkomen met de gespecificeerde CSS-selectie 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 een 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 of geef de titel van het document in. |
URL | Geef de volledige URL van het HTML-document terug. |
write() | Schrijf HTML-expressies of JavaScript-code naar het document. |
writeln() | Gelijk aan write(), maar met een nieuwe regel toegevoegd achter elke zin. |
Document object beschrijving
Het HTMLDocument-interface breidt het DOM Document-interface uit en definieert HTML-gebruikte eigenschappen en methoden.
Vele eigenschappen en methoden zijn HTMLCollection-objecten (daadwerkelijk zijn ze leesbare arrays die met naam kunnen worden geïndexeerd), waarin verwijzingen naar ankers, formulieren, koppelingen en andere script-elementen worden opgeslagen.
Deze verzamelattributen zijn afkomstig van het 0-niveau DOM. Ze zijn reeds Document.getElementsByTagName() is vervangen, maar wordt nog vaak gebruikt omdat het zo handig 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 definieerde 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 Window Scherm
- Volgende pagina HTML Element