Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the relationship between JavaScript and dom

Shulou Source: shulou.com Published: 2022-06-03 07:27:10 11月15日 Update

This article mainly explains "what is the relationship between JavaScript and dom". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the relationship between JavaScript and dom".

Dom (document object Model) is a part of JavaScript, which provides JavaScript with methods and interfaces to deal with web content; all operations on web pages by JavaScript are done through DOM.

The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.

A complete JavaScript consists of the following three parts:

ECMAScript: provides the syntax and basic objects of the language

Document object Model (DOM): provides methods and interfaces for dealing with 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 program interface (API) of HTML and XML. DOM will plan the entire page into a document at a node level. Each part of a HTML or XML page is a derivative of a node.

DOM represents documents by creating trees, giving developers unprecedented control over the content and structure of documents. Nodes (getElementById, childNodes, appendChild, innerHTML) can be easily deleted, added, and replaced with DOM API.

The relationship between DOM and JavaScript

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

DOM is not a programming language, but there would be no web page operation without the DOM,JavaScript language. Everything we do to the web page with JavaScript is done through DOM.

The following code shows the difference between JavaScript and DOM more visually. The part of the code marked red is DOM:

Var Tags = document.getElementsByTagName ("a")

For (var I = 0; I < Tags.length; iTunes +)

{

Alert ("Href of this an element is:" + tags [I] .href + "\ n")

}

In this way, it can be clear at a glance which are the core JavaScript, which are DOM, and what their respective roles are. (the code is not explained here).

So there is an approximate equation:

Web or XML page = DOM + JS (scripting language)

Thank you for your reading, the above is the content of "what is the relationship between JavaScript and dom". After the study of this article, I believe you have a deeper understanding of what the relationship between JavaScript and dom is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Document object content model web page language code interface part method node page learning that is core browser programming language processing browsing programming Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi NVidia Linux Shulou Information Microsoft