当前位置:网站首页>On BOM and DOM (3): DOM node operation - element style modification and DOM content addition, deletion, modification and query
On BOM and DOM (3): DOM node operation - element style modification and DOM content addition, deletion, modification and query
2022-06-24 06:36:00 【Army Zhou】
Operation node , First you have to select the node , You have to know the node selector and DOM Node lookup
DOM Node selector
W3C It provides more convenient methods and attributes for locating nodes
getElementById() | One parameter : Element label ID |
|---|---|
getElementsByTagName() | One parameter : Element tag name |
getElementsByName() | One parameter :name Property name |
getElementsByClassName() | One parameter : A string containing one or more class names |
querySelector() | receive CSS Selector , Returns the first element matched to , No rules null |
querySelectorAll() | receive CSS Selector , Returns an array , No return [] |
DOM Node relationship and node lookup
Traversing the node tree , Method involved
hasChildNodes() | Contains one or more nodes true |
|---|---|
contains() | If it is a descendant node, return true |
isEqualNode() | Two nodes refer to the same object : The reference of the incoming node and the reference node returns for the same object true |
isSameNode() | It refers to whether two nodes are of the same type , Have equal attributes/childNodes etc. |
compareDocumentPostion() | Determine the relationships between nodes |
parentNode | Parent node |
parentElement | Parent node label element |
childNodes | All child nodes |
children | First level sub node |
firstChild | First child node ,Node Objects form |
firstElementChild | The first child tag element |
lastChild | The last child node |
lastElementChild | The last child tag element |
previousSibling | Last sibling node |
previousElementSibling | Last brother tag element |
nextSibling | Next sibling node |
nextElementSibling | Next brother tag element |
childElementCount | The number of sub elements in the first layer ( Excluding text nodes and comments ) |
ownerDocument | The document node pointing to the entire document |
node And element The difference between
- element Is contained in node Inside , its nodeType yes 1
- parentElement The match is parent by element The situation of , and parentNode The match is parent by node The situation of .
- When the parent node nodeType No 1, That is not element Node words , its parentElement It would be null
The node relationship diagram is as follows
DOM Node style operation
DOM Node style operation , You can set class, Set the style
operation className
className: Return to node style , You can set className="demo1 class2"
classList : Returns an array of all class names
- add ( add to )
- contains ( Is there any class, There is returned true, Otherwise return to false)
- remove( Delete )
- toggle( Delete if it exists , Otherwise, add )
operation style Method
style.cssText | But for style Read and write the code in |
|---|---|
style.item() | Returns the value of a given location CSS Name of property |
style.length | style Number of parameters in code block |
style.getPropertyValue() | Returns the string value of the given property |
style.getPropertyPriority() | Check whether the given property is set !important, Return is set "important"; Otherwise, an empty string is returned |
style.removeProperty() | Delete the specified attribute |
style.setProperty() | Set properties , There are three parameters : Set property name , Setting property values , Is it set to "important"( Don't write or write "") |
DOM Content manipulation
Text node TEXT
innerText | All plain text content , Include text in child Tags |
|---|---|
outerText | And innerText similar |
innerHTML | All child nodes ( Including elements 、 Comments and text nodes ) |
outerHTML | Returns its own node and all its children |
textContent | And innerText similar , Returned content with style |
data | Text content |
length | Text length |
createTextNode() | Create text |
normalize() | Remove the space between the text and the text |
splitText() | Division |
appendData() | Additional |
deleteData(offset,count) | from offset Start deletion at the specified location count Characters |
insertData(offset,text) | stay offset Insert at the specified location text |
replaceData(offset,count,text) | Replace , from offset Start to offscount The text at is deleted text Replace |
substringData(offset,count) | Extract from ffset Start to offscount The text at |
innerText、innerHTML、outerHTML、outerText
- innerText: Represents the text between the start tag and the end tag
- innerHTML: That represents all elements and text of an element HTML Code
- outerText: The difference from the former is that the whole target node is replaced , Question return and innerText The same thing
- outerHTML: The difference from the former is that the whole target node is replaced , Returns the complete of the element HTML Code , Including the element itself
Document nodes Document
document.documentElement | Represents the <html> Elements |
|---|---|
document.body | Represents the <body> Elements |
document.doctype | representative <!DOCTYPE> label |
document.head | Represents the <head> Elements |
document.title | representative <title> The text of the element , Modifiable |
document.URL | Current page URL Address |
document.domain | The domain name of the current page |
document.charset | The character set used by the current page |
document.defaultView | Returns the current document Object is associated with window object , No return null |
document.anchors | All bands in the document name Attribute <a> Elements |
document.links | All bands in the document href Attribute <a> Elements |
document.forms | All in the document <form> Elements |
document.images | All in the document <img> Elements |
document.readyState | Two values :loading( Loading document )、complete( Finished loading document ) |
document.compatMode | Two values :BackCompat: Standard compatibility mode off 、CSS1Compat: Standard compatibility mode on |
write()、writeln()、open()、close() | write() The text is output to the screen as is 、writeln() Line feed after output 、open() Empty content and open new document 、close() Close the current document , Next time I write a new document |
DOM Basic operational mind map
Reference article :
ECMAScript、BOM、DOM( The core 、 Browser object model and document object model )https://www.cnblogs.com/best/p/8028168.html
JavaScript Learning summary ( 3、 ... and )BOM and DOM Detailed explanation https://segmentfault.com/a/1190000000654274
Javascript operation BOM and DOM Detailed explanation (1) https://blog.csdn.net/openbox2008/article/details/85260063
JavaWeb Learning summary :JavaScript(BOM and DOM) https://blog.csdn.net/weixin_42384085/article/details/99807198
HTML DOM Event object https://www.w3school.com.cn/jsref/dom_obj_event.asp
XML DOM - Element object https://www.w3school.com.cn/xmldom/dom_element.asp
JAVAScript in DOM And BOM The difference analysis of https://www.cnblogs.com/fjner/p/5892325.html
Reprint This station article 《 We can talk BOM and DOM(3):DOM Node operation - Element style modification and DOM Content addition, deletion, modification and query 》, Please indicate the source :https://www.zhoulujun.cn/html/webfront/SGML/xml/2020_0317_8345.html
边栏推荐
- Implementation of code rate and frame rate statistics in easyplayer RTSP player
- Source code analysis of current limiting component uber/ratelimit
- Kubernets traifik proxy WS WSS application
- Enter the software test pit!!! Software testing tools commonly used by software testers software recommendations
- leetcode:84. 柱状图中最大的矩形
- Easyscreen live streaming component pushes RTSP streams to easydss for operation process sharing
- 35岁危机?内卷成程序员代名词了
- In the half year, there were 2.14 million paying users, a year-on-year increase of 62.5%, and New Oriental online launched its private domain
- What are the categories of edge computing devices
- How to batch move topics to different categories in discover
猜你喜欢

云上本地化运营,东非第一大电商平台Kilimall的出海经
![[fault announcement] one stored procedure brings down the entire database](/img/7c/e5adda73a077fe4b8f04b59d1e0e1e.jpg)
[fault announcement] one stored procedure brings down the entire database

C语言学生管理系统——可检查用户输入合法性,双向带头循环链表

ServiceStack. Source code analysis of redis (connection and connection pool)
Fault analysis | using --force to batch import data leads to partial data loss

Enter the software test pit!!! Software testing tools commonly used by software testers software recommendations

目标5000万日活,Pwnk欲打造下一代年轻人的“迪士尼乐园”

基于三维GIS系统的智慧水库管理应用
![Command ‘[‘where‘, ‘cl‘]‘ returned non-zero exit status 1.](/img/2c/d04f5dfbacb62de9cf673359791aa9.png)
Command ‘[‘where‘, ‘cl‘]‘ returned non-zero exit status 1.

leetcode:84. 柱状图中最大的矩形
随机推荐
Analysis of official template of wechat personnel recruitment management system (II)
What are the categories of edge computing devices
Intranet environment request Tencent cloud 3.0 API details
You don't have to spend a penny to build a wechat official website in a minute
What is an enterprise mailbox domain name? How to register an enterprise mailbox domain name
Web automated testing (2): choose selenium advantage? Comparison with phantomjs/qtp/monkey
Small programs import Excel data in batches, and cloud development database exports CVS garbled code solution
Actual combat | how to deploy flask project using wechat cloud hosting
Replacing human eyes -- visual inspection technology
MySQL concept - View
Papamelon 11 number of calculation permutation [combinatorics]
Quick reference table of PHP security configuration maintained by OWASP
How to build a website with a domain name? Is the domain name very cheap
How to build a website after having a domain name? Can you ask others to help register the domain name
Architecture: rest and HATEOAS
Analysis of official template of wechat personnel recruitment management system (I)
How to apply 5g smart pole to smart highway
Innovating the security service mode, deeply convinced that the organization has been equipped with a "continuous online expert group"
Excel data extraction technique: a universal formula for extracting numbers from mixed text
CLB unable to access / access timeout troubleshooting