4

Is the DOM API part of he JavaScript language, more specifically are the methods such as document.getElementById(), window.scroll() etc part of JavaScript?

If not then how do these work?

4
  • 1
    is part of JavaScript? Actually no. Its not a part of language but of window. Document/window are objects that are associated with the rendered window and are available by default but its implementation over JS and not a part of language. A simple test, open a node console(not browser console) and type document or window. It will throw error Commented Nov 5, 2019 at 9:11
  • I guess while they are available in the language, they are more part of the browser API which allows developers to interact with that particular environment. In Node for example, there wouldn't necessarily be a 'window'. Commented Nov 5, 2019 at 9:13
  • 1
    The DOM API is not part of the JavaScript language but it is exposed to JavaScript by the browser. The JavaScript language specification explicitly allows the host environment to define arbitrary global variables. Commented Nov 5, 2019 at 9:19
  • A useful article: html5rocks.com/en/tutorials/internals/howbrowserswork/… Commented Nov 5, 2019 at 9:26

5 Answers 5

3

The DOM is an object-oriented representation of the web page, which can be modified with a scripting language such as JavaScript. So methods like document.getElementById(), window.scroll() etc are not part of the DOM but they are used by the scripting language to modify the DOM using the global objects like document and window which are usually termed as Browser Object Model (BOM). So most browsers implement these methods to specify how they affect the DOM.

Sign up to request clarification or add additional context in comments.

Comments

1

Is document or window object part of Javascript?

Simple answer is No. Its an implementation of javascript.


How does this works?

Considering its in relation to web, this is the assumed flow (Terminology is a bit lame. Please forgive me for that).

The process start with a Browser application.

A browser window has few components associated to it:

  • Window
  • Dev tools
  • Client storage
  • Network communication

However, a browser window only understands JS, CSS and HTML. So to create a bridge for communication between these modules, browser injects pre craeted objects implemented in javascript.

Such objects include:

  • document: To communicate with rendered DOM tree.
  • window: To update properties of rendered window.
  • sessionStorage, localStorage etc: for client storage.
  • XmlHttpRequest: for server communication.

So if you try to access these objects in Node which is an independent JS session, you will get reference error.

References:

Comments

0

When a web page is loaded, the browser creates a Document Object Model of the page, which is an object oriented representation of an HTML document that acts as an interface between JavaScript and the document itself. This allows the creation of dynamic web pages,[9] because within a page JavaScript can:

add, change, and remove any of the HTML elements and attributes change any of the CSS styles react to all the existing events create new events

The HTML DOM can be accessed with JavaScript (and with other programming languages).

In the DOM, all HTML elements are defined as objects.

The programming interface is the properties and methods of each object.

1 Comment

This is not what OP asked.
0

The W3C Document Object Model (DOM) is a platform and language-neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document. In other words: The HTML DOM is a standard for how to get, change, add, or delete HTML elements.

On the other hand, The Javascript DOM (Document Object Model) is an interface that allows developers to manipulate the content, structure, and style of a website.

So, document.getElementById(), window.scroll() are from DOM API and can be accessed by using JavascriptDOM interface.

You can have a good overview of this concept by going through the following articles

Introduction to DOM

HTML DOM API

Comments

0

DOM API is not part of the JavaScript language. They are separate entities. The DOM is just a set of functionalities that browser exposes via global object (window) to the scripts which are being executed in the browser environment. In other environments - such as node, the DOM API is not necessarily available. You can read more about this topic here:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.