当前位置:网站首页>DOM day_ 01 (7.7) introduction and core operation of DOM
DOM day_ 01 (7.7) introduction and core operation of DOM
2022-07-27 00:48:00 【Add 1 bed of bedding】
DOM: Document Object Model Document object model
HTML CSS: The essence is JS The grammar sugar of
There are two functions of browser :
1. hold HTML and CSS This grammatical sugar writing , convert to JS The object of
2. hold JS object Render to page
One 、DOM Trees
hold HTML Code , Display in the form of diagram . It looks like a tree
node: node. html Each element in is called a node . Because of different functions Yes Different node classification names

First time to know dom
Whole HTML, It will be parsed into document object , The content finally displayed on the browser , The essence is a JS object , and HTML As a grammar sugar , Only simple page configuration , Study DOM Purpose : Put aside grammar sugar , Directly operate the page itself Essential code . You can operate the page more flexibly .

DOM effect
DOM The key role of : make up HTML Ability not possessed -- dynamic
Purpose : Put time in id=time Print in the element of

Two 、 Element reading
1. Fixed element read
DOM The core operation of is just two things :
1. Find the element to manipulate -- There are many official solutions
2. Properties of the operation element

2.css Selector reads elements
utilize css Selectors yes Universal solution for finding elements
querySelectorAll: Find all the elements that meet the conditions through the selector
// The prototype of the return value is NodeList, Is an array of classes / Pseudo array
// however : Among them is forEach Method can be used to traverse

3、 ... and 、class operation
In actual development , There are two styles style( Use less ) and class( Use more )

By modifying the className, Change the style after the click event

classList
classList: hold class Object after attribute encapsulation
Its prototype has various methods , It can be operated conveniently class
1.add: increase / add to new class value
advantage : Compared with self modification className, The use method is more safe and reliable
2.remove: Delete
3. toggle: Switch

practice
First determine the style

write in DOM,DOM The core operation of : First find the element you want to operate , Operate him

3、 ... and 、DOM Some applications of
1. Expand and hide the menu

practice

2. Page number indication point

summary
DOM: Document object model
HTML The essence is JS The grammar sugar of , The browser will convert it into document object ,HTML Can only bear the display of static pages ,DOM Direct manipulation JS object , Can be made up to complete dynamic The content display of ( make up HTML The impossible )
Its core operation is two steps :
1. Found element
(1) Find fixed elements : headbodydocumentElement-html
(2) Find by relationship
- children: All sub elements
- parentElement: Parent element
- nextElementSibling: Next brother element
(3) Search by characteristics
- id: getElementById
- Tag name : getElementsByTagName
(4) utilize css Selector search ( universal )
- querySelector: The return value is the element
- querySelectorAll: The return value is an array of classes , Need to traverse
2. Properties of the operation element
(1)style: inline style
(2)class:
- className: Namely class Attribute Ontology
- classList: Yes class Encapsulated objects , There are many operations class Methods
(3) event : All are on The properties of the beginning
- onclick : Click event
边栏推荐
- [HFCTF2020]EasyLogin
- JSCORE day_02(7.1)
- Medical data of more than 4000 people has been exposed for 16 years
- JSCORE day_01(6.30) RegExp 、 Function
- [NPUCTF2020]ezinclude
- 【AcWing第61场周赛】
- ArcGIS and CASS realize elevation points of cross-section Exhibition
- C language is more than a variety of descriptions of size. Don't stick to one way of writing
- [qt] meta object system
- 用New,delete和用malloc,free申请,释放堆区空间
猜你喜欢

Application of encoding in XSS
![[NPUCTF2020]ezinclude](/img/24/ee1a6d49a74ce09ec721c1a3b5dce4.png)
[NPUCTF2020]ezinclude
![[watevrCTF-2019]Cookie Store](/img/24/8baaa1ac9daa62c641472d5efac895.png)
[watevrCTF-2019]Cookie Store
![[CISCN2019 总决赛 Day2 Web1]Easyweb](/img/36/1ca4b6cae4e0dda0916b511d4bcd9f.png)
[CISCN2019 总决赛 Day2 Web1]Easyweb

Matlab based medical imaging technology filtering backprojection simulation, including direct backprojection, S-L filtering, R-L filtering, LeWitt filtering
![[红明谷CTF 2021]write_shell](/img/f5/c3a771ab7b40311e37a056defcbd78.png)
[红明谷CTF 2021]write_shell

postman的使用
![[HFCTF2020]EasyLogin](/img/23/91912865a01180ee191a513be22c03.png)
[HFCTF2020]EasyLogin
![[acwing game 61]](/img/83/c9a43536705451a60252720fc41d14.jpg)
[acwing game 61]

QML type system
随机推荐
【3. 基础搜索与图论初识】
MySql
[3. VIM operation]
2022.DAY600
[4.4 detailed explanation of fast power and inverse element of fast power]
动态联编和静态联编、以及多态
AutoCAD的卸载后重新安装,删除注册表的详细过程
关于Thymeleaf的表达式
JSCORE day_04(7.5)
JSCORE day_05(7.6)
Two methods of automated testing XSS vulnerabilities using burpsuite
【AcWing第61场周赛】
[qt] meta object system
[Network Research Institute] attackers scan 1.6 million WordPress websites to find vulnerable plug-ins
[LeetCode] 无重复最长字符串
【2. Tmux 操作】
Crop TIF image
[4.6 detailed explanation of Chinese remainder theorem]
CDs simulation of minimum dominating set based on MATLAB
Friend友元函数以及单例模式