Reputation: 53
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?
Upvotes: 3
Views: 1410
Reputation: 3116
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:
Upvotes: 0
Reputation: 24915
Is
document
orwindow
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:
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.
Upvotes: 1
Reputation: 395
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.
Upvotes: 3
Reputation: 2134
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
Upvotes: 0
Reputation: 382
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.
Upvotes: 0