Document

Обновлено: 27.03.2023

The Document Object

Коли документ HTML завантажується у веб-браузер, він стає об’єктом документа .

Об’єкт документа є кореневим вузлом документа HTML.

Об'єкт документа є властивістю об'єкта вікна .

Доступ до об’єкта документа здійснюється за допомогою:

window.documentабо простоdocument

Властивості та методи об’єкта документа

Для документів HTML можна використовувати такі властивості та методи:

  • activeElement

    activeElement

    Returns the currently focused element in the document

  • addEventListener()

    addEventListener()

    Attaches an event handler to the document

  • adoptNode()

    adoptNode()

    Adopts a node from another document

  • anchors

    anchors

    Deprecated

  • applets

    applets

    Deprecated

  • baseURI

    baseURI

    Returns the absolute base URI of a document

  • body

    body

    Sets or returns the document's body (the <body> element)

  • charset

    charset

    Deprecated

  • characterSet

    characterSet

    Returns the character encoding for the document

  • close()

    close()

    Closes the output stream previously opened with document.open()

  • cookie

    cookie

    Returns all name/value pairs of cookies in the document

  • createAttribute()

    createAttribute()

    Creates an attribute node

  • createComment()

    createComment()

    Creates a Comment node with the specified text

  • createDocumentFragment()

    createDocumentFragment()

    Creates an empty DocumentFragment node

  • createElement()

    createElement()

    Creates an Element node

  • createEvent()

    createEvent()

    Creates a new event

  • createTextNode()

    createTextNode()

    Creates a Text node

  • defaultView

    defaultView

    Returns the window object associated with a document, or null if none is available.

  • designMode

    designMode

    Controls whether the entire document should be editable or not.

  • doctype

    doctype

    Returns the Document Type Declaration associated with the document

  • documentElement

    documentElement

    Returns the Document Element of the document (the <html> element)

  • documentMode

    documentMode

    Deprecated

  • documentURI

    documentURI

    Sets or returns the location of the document

  • domain

    domain

    Returns the domain name of the server that loaded the document

  • domConfig

    domConfig

    Deprecated

  • embeds

    embeds

    Returns a collection of all <embed> elements the document

  • execCommand()

    execCommand()

    Deprecated

  • forms

    forms

    Returns a collection of all <form> elements in the document

  • getElementById()

    getElementById()

    Returns the element that has the ID attribute with the specified value

  • getElementsByClassName()

    getElementsByClassName()

    Returns an HTMLCollection containing all elements with the specified class name

  • getElementsByName()

    getElementsByName()

    Returns an live NodeList containing all elements with the specified name

  • getElementsByTagName()

    getElementsByTagName()

    Returns an HTMLCollection containing all elements with the specified tag name

  • hasFocus()

    hasFocus()

    Returns a Boolean value indicating whether the document has focus

  • head

    head

    Returns the <head> element of the document

  • images

    images

    Returns a collection of all <img> elements in the document

  • implementation

    implementation

    Returns the DOMImplementation object that handles this document

  • importNode()

    importNode()

    Imports a node from another document

  • inputEncoding

    inputEncoding

    Deprecated

  • lastModified

    lastModified

    Returns the date and time the document was last modified

  • links

    links

    Returns a collection of all <a> and <area> elements in the document that have a href attribute

  • normalize()

    normalize()

    Removes empty Text nodes, and joins adjacent nodes

  • normalizeDocument()

    normalizeDocument()

    Deprecated

  • open()

    open()

    Opens an HTML output stream to collect output from document.write()

  • querySelector()

    querySelector()

    Returns the first element that matches a specified CSS selector(s) in the document

  • querySelectorAll()

    querySelectorAll()

    Returns a static NodeList containing all elements that matches a specified CSS selector(s) in the document

  • readyState

    readyState

    Returns the (loading) status of the document

  • referrer

    referrer

    Returns the URL of the document that loaded the current document

  • removeEventListener()

    removeEventListener()

    Removes an event handler from the document (that has been attached with the addEventListener() method)

  • renameNode()

    renameNode()

    Deprecated

  • scripts

    scripts

    Returns a collection of <script> elements in the document

  • strictErrorChecking

    strictErrorChecking

    Deprecated

  • title

    title

    Sets or returns the title of the document

  • URL

    URL

    Returns the full URL of the HTML document

  • write()

    write()

    Writes HTML expressions or JavaScript code to a document

  • writeln()

    writeln()

    Same as write(), but adds a newline character after each statement