Differences and connections between JavaScript and HTMLDOM and the relationship between Javascript and DOM _ javascript skills

Source: Internet
Author: User
This article mainly introduces the differences between JavaScript and HTMLDOM and related information about the relationship between Javascript and DOM. For more information, see the following differences:

Javascript

JavaScript is the most popular Browser Scripting language on the Internet. Easy to use! You will love it!

JavaScript is used by millions of web pages to improve design, validate forms, detect browsers, create cookies, and more applications.

HTML DOM

Html dom is W3C standard (abbreviated as Document Object Model for HTML ).

Html dom defines a series of standard objects for HTML and standard methods for accessing and processing HTML documents.

With DOM, you can access all HTML elements, along with the text and attributes they contain. You can modify and delete the content and create new elements.

Html dom is independent of platform and programming language. It can be used by any programming languages such as Java, JavaScript, and VBScript.

Contact:

JavaScript allows you to refactor the entire HTML document. You can add, remove, change, or rearrange projects on the page.

To change something on the page, JavaScript needs to obtain an entry to access all elements in the HTML document. This entry, along with the methods and attributes for adding, moving, changing, or removing HTML elements, is obtained through the Document Object Model (DOM ).
Javascript uses html dom to obtain, change, and Create HTML elements, so as to beautify pages and operate on page elements. Therefore, the most common in Javascript is a variety of html dom elements and their respective attributes. In addition to these DOM elements, Javascript has its own objects, such as arrays.

To put it simply, Javascript is mainly used to manipulate html dom. The two are different.
Javascript is a language, and DOM is a model that can dynamically modify documents in various languages (not only js, but also php.

The following is a detailed description of the relationship between JavaScript and DOM.

JavaScript and browser work

1. the browser obtains and loads your page and parses its content from top to bottom.

When JavaScript is encountered, the browser will parse the code, check its correctness, and then execute the code.

The browser also creates an internal HTML page model (DOM ).

2. JavaScript continues to be executed. Use DOM to check the page, complete the modification, and accept the event from the page, or ask the browser to obtain other data from the Web server.

How does JavaScript interact with pages?

JavaScript is code and HTML is a tag. It's totally different.

How can they interact?

The answer is to use the Docunment Object Model (DOM ).

DOM provides a consistent way to access the structure and content of HTML through code on all browsers.

1. When the browser loads a page, the browser parses HTML and creates an internal model of the document, which contains all the elements marked by HTML.

2. JavaScript can interact with DOM (JavaScript uses DOM to create or delete elements, etc)

Document is an object that reflects HTML. It changes the DOM state by calling the document method, that is, changing the HTML page.

3. When JavaScript modifies the DOM, the browser dynamically updates the page.

Homemade DOM

MATERIALS: HTML5 pages in the correct format, WEB browsers

Practice:

1. Create a document node at the top

2. Obtain the top-level elements of the HTML page.Element to add it to the DOM as a child node of the document

3. For each nested element in the current element, add this element as a child node of the current element to the DOM

4. For the newly added elements, perform step 3 and repeat until all elements are processed.

The HTML page is as follows: 

   DOM 
  
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.