Home Web Front-end JS Tutorial Some summary of using DOM

Some summary of using DOM

Mar 14, 2018 pm 02:53 PM
use

This time I will bring you some summary of using DOM, what are the precautions when using DOM, the following is a practical case, let's take a look.

DOM is a language-neutral API for accessing html and xml documents. DOM1 level visualizes html and xml documents as a jagged node tree. You can use javascript to manipulate this number of nodes, thereby changing the appearance and structure of the Dieten document.

DOM is composed of various nodes. A brief summary is as follows:

The most basic node type is Node, which is used to abstractly represent an independent part of the document. All other types are Inherited from Node.

.Document type represents the entire document, which is the root node of a group of hierarchical nodes. In JavaScript, the document object is an instance of Document. Using the document object, there are many ways to query and obtain nodes. First, it can get the child nodes of the document, such as var hetml=document.documentElement;//Get the reference to html. The second is that it can obtain document information, for example: var original=document.tittle; document.tittle=”new title”;//Set the title of the document. The third is to find elements, including getElementById(), and getElementByName();

Element nodes represent all elements relative to html and xml, and can be used to operate the content and attributes of these elements.

There are also some node types, which respectively represent document content (text), comments (comment), document type (Documentype), CDATA area (CDATAsection) and document fragments.

The operation of accessing the DOM is intuitive in many cases, but there are still some problems when processing script and style elements. Since these two elements contain script and style information, browsers usually treat them as Discrimination.
The key to understanding DOM is to understand the impact of DOM on performance. DOM is often the most expensive part of the program in JavaScript, and because there are many problems accessing Nodelist, NoList causes the most problems, and NdeList objects are dynamic. This means that every time you access the NodeList object, you have to run a query. In view of this, the best way is to reduce DOM operations.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

js design pattern - the use of singleton pattern

Why should the front end use modularity?

The above is the detailed content of Some summary of using DOM. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use magnet links How to use magnet links Feb 18, 2024 am 10:02 AM

How to use magnet links

How to use mdf and mds files How to use mdf and mds files Feb 19, 2024 pm 05:36 PM

How to use mdf and mds files

What software is crystaldiskmark? -How to use crystaldiskmark? What software is crystaldiskmark? -How to use crystaldiskmark? Mar 18, 2024 pm 02:58 PM

What software is crystaldiskmark? -How to use crystaldiskmark?

How to download foobar2000? -How to use foobar2000 How to download foobar2000? -How to use foobar2000 Mar 18, 2024 am 10:58 AM

How to download foobar2000? -How to use foobar2000

How to use NetEase Mailbox Master How to use NetEase Mailbox Master Mar 27, 2024 pm 05:32 PM

How to use NetEase Mailbox Master

How to use Baidu Netdisk app How to use Baidu Netdisk app Mar 27, 2024 pm 06:46 PM

How to use Baidu Netdisk app

How to use Xiaoai Speaker How to connect Xiaoai Speaker to mobile phone How to use Xiaoai Speaker How to connect Xiaoai Speaker to mobile phone Feb 22, 2024 pm 05:19 PM

How to use Xiaoai Speaker How to connect Xiaoai Speaker to mobile phone

Simple guide to pip mirror source: easily master how to use it Simple guide to pip mirror source: easily master how to use it Jan 16, 2024 am 10:18 AM

Simple guide to pip mirror source: easily master how to use it

See all articles