Home  >  Article  >  Web Front-end  >  What is the relationship between JavaScript and dom

What is the relationship between JavaScript and dom

青灯夜游
青灯夜游Original
2021-10-09 15:49:392420browse

Dom (Document Object Model) is a component of JavaScript. It provides JavaScript with methods and interfaces for processing web page content; all operations performed by JavaScript on web pages are performed through the DOM.

What is the relationship between JavaScript and dom

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

Complete JavaScript is composed of the following three parts:

  • Core (ECMAScript): Provides the syntax and basic objects of the language;

  • Document Object Model (DOM): Provides methods and interfaces for processing web content;

  • Browser Object Model (BOM): Provides methods and interfaces for interacting with browsers .

Document Object Model (DOM):

DOM (Document Object Model) is the application programming interface (API) for HTML and XML. DOM will lay out the entire page into a document composed of node hierarchies. Each part of an HTML or XML page is a derivative of a node.

DOM represents a document by creating a tree, giving developers unprecedented control over the content and structure of the document. Nodes can be easily removed, added and replaced using the DOM API (getElementById, childNodes, appendChild, innerHTML).

The relationship between DOM and JavaScript

We all know that JavaScript is a programming language, and .js files are codes written in JavaScript, so what role does DOM play in it? What kind of role?

DOM is not a programming language, but without DOM, the JavaScript language would not have any web page operations. All operations we perform on web pages using JavaScript are performed through the DOM.

The following is a piece of code to more intuitively display the difference between JavaScript and DOM. The part marked in red in the code is the DOM:

var Tags = document.getElementsByTagName( "a");
for(var i = 0; i < Tags.length; i )
                                    alert("Href of this a element is: "
Tags[i].href "\n"); }

In this way, which ones are core JavaScript and which ones are DOM, what role do they play? It can be seen at a glance. (The code will not be explained here).


So there is such an approximate equation:

web or XML page = DOM JS (scripting language)

[Recommended learning :

javascript advanced tutorial

The above is the detailed content of What is the relationship between JavaScript and dom. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn