. The practical and commonly used parts of DOM operations are selected, and the practical but obviously compatible parts are omitted
2.The type attribution of DOM attributes and methods may not be completely accurate
3. Some general compatibility and features are marked (mainly ie8-9 up and down)
Node type
Node type |
Node value |
##Label node(Element) | 1 |
Attribute node(Attr ) | 2 |
Text Node(Text) | 3 |
CDATA Node(CDATASetion) | 4 |
Entity Reference Node(EntityReference) | 5 |
Entity Node(Entity) | 6 |
ProcessingInstruction | 7 |
Comment Node(Comment) | 8 |
Document Node(Document) | 9 |
Document Type Node(DocumentType) | 10 |
Document Fragment Node (DocumentFragment) | 11 |
DTD Declaration Node (Notation) | 12 |
Node type
##Attribute
Description |
|
nodeType
Node type |
|
nodeName
Node name |
|
nodeValue
Node value |
|
childNodes
Child nodes |
|
parentNode
Parent Node |
|
ownerDocument
Document Node |
|
previousSibling
Previous Node | |
nextSibling
Next node |
|
firstChild
First child node |
|
lastChild
The last child node |
|
Document type
Attribute
Description |
|
documentElement
html tag |
|
head[Insufficient compatibility ]
head tag |
|
body
body tag |
|
URL
current Page url |
|
referrer
Source page url |
| ##domain[can be modified]
Page domain name |
| images
All picture collection |
| cookie
cookie information |
| title
Page title |
| activeElement
Current focus element |
| documentMode
Document Mode |
| readyState
Document Status |
| doctype
Document type declaration |
| scripts
Script collection |
| forms
form tag collection |
| children
A collection of child nodes of element type |
| defaultView
The window object associated with the document |
|
Method
Description |
|
##getElementById()
Return the element corresponding to the id
|
getElementsByName() |
Return the collection of corresponding name elements
|
getElementsByTagName() |
Return the collection of elements corresponding to the tag name
|
getElementsByClassName() |
Return the collection of elements with the specified class name
|
querySelector( ) |
Returns the first element that matches the selector
|
querySelectorAll() |
Returns the set of elements that matches the selector
|
createElement() |
Create element node
|
createTextNode() |
Create text node
|
createAttribute() |
Create attribute node
|
createComment() |
Create comment node
|
createDocumentFragment() |
Create an empty DocumentFragment object
|
matchesSelector()[Insufficient compatibility, prefix required] |
Whether the selector matches Element matching
|
write()[cursor does not wrap after output] |
Document text writing
|
writeIn()[ Cursor wraps after output] |
Document text is written
|
implementation.hasFeature(feature, version) |
Feature monitoring
|
| Element type
Attribute
Description
|
|
id
id
|
className |
Class name
|
title |
title
|
style |
Set or return the style attribute of the element
|
innerHTML |
Set or return the element's style attribute Content
|
outerHTML[including self] |
Set or return the content of the element
|
textContent[ie-innerText] |
Set or return the text content
|
contentEditable |
Set or return the editable state of the element
| ##isContentEditable | Whether it is editable
| childElementCount | Number of child element nodes
| firstElementChild | First child element node
| lastElementChild | Last child element node
| previousElementSibling | Previous element node
| nextElementSibling | Next element node
|
Method |
Description |
Return |
focus() |
Set focus |
|
blur() |
Lost focus |
|
appendChild(node) |
Insert after the child node list |
New node |
insertBefore(node, reference node) | Insert node before reference node |
Insert node |
removeChild(node) |
Node deletion |
Deleted node |
replaceChild(node, replaced node) |
Node replacement |
Replaced node |
cloneNode(Boolean value) |
Copy Node |
Clone Node |
importNode(Node, Boolean value) |
From document A Obtain node a and import it into document B (similar to cloneNode method) |
|
##contains (node) | Whether the node is a child of the calling node Level | Boolean value |
##hasFocus()
Whether the focus has been obtained |
Boolean value |
|
hasChildNodes()
Whether there are child nodes |
Boolean value |
|
isDefaultNamespace(url)
Whether it is specified Namespace |
Boolean value |
| ##isEqualNode(node)
Whether two elements are equal | Boolean value |
| isSupported(feature, version)
Whether a feature is supported | Boolean value |
|
Attr type
Attribute
Description |
|
##name
Attribute name
|
value |
Attribute value
|
isId |
Whether it is an id type
|
specified |
Whether the attribute is specified
|
length |
Attribute length
|
attributes |
Attribute collection
|
|
Method
Description
|
|
getAttribute()
Get the attribute value
|
getAttributeNode() |
Get the attribute node
|
setAttribute() |
Set attribute value
|
setAttributeNode() |
Set attribute node
| removeAttribute() |
Remove attribute
|
removeAttributeNode()[ie not supported] |
Remove attribute node
|
hasAttribute() |
Whether the specified attribute exists
|
hasAttributes() |
Whether the attribute exists
|
| Text type
Method
Description
|
|
appendData(text)
Add text to the end of the node
|
deleteData(position, quantity) |
Delete n characters starting from the specified position
|
insertData(position, text) |
Insert text from the specified position
|
replaceData(position, quantity, text) |
Replace the text from offset position to offset+count with text
|
splitText(position) |
Split the current text node from the specified position Into two text nodes
|
substringData(position, quantity) |
Intercept the string starting from offset position to offset+count
|
normalize() |
Merge adjacent text nodes and delete empty text nodes
|
| Table operation
table Element
Attribute Method
Description
|
|
caption
caption element pointer
|
tBodies |
tbody collection
|
tFoot |
tfoot collection
|
tHead |
thead element
|
rows |
Collection of all rows in the table
|
createTHead() |
Create element, place it in the table, return reference
| ##createTFoot() | Create< tfoot> element, put it into the table, return the reference
| createCaption() | Create the caption element, put it into the table, return the reference
| deleteTHead() | Delete thead element
##deleteTFoot() |
Delete tfoot element |
deleteCaption() |
Delete the caption element |
deleteRow(pos) |
Delete the row at the specified position |
insertRow(pos) |
Insert a row at the specified position in the row collection |
| tbody element |
Attribute methodDescription
| ##rows | tbody all row collection
deleteRow(pos) | Delete the row at the specified position |
insertRow(pos) | To the row collection Insert a row at the specified position and return the reference |
##tr element |
|
Attribute method
Description
cells |
trAll cell collection |
deleteCell(pos)
Delete the cell at the specified position |
|
insertCell(pos)
Insert a cell at the specified position in the cell collection and return the reference |
|
Style operation
Access element style
Attribute method (dom.style) |
Description |
cssText |
Returns the string form of all styles in the style attribute |
length |
Returns the number of CSS attributes in the element |
parentRule |
Returns the CSSRule object of CSS information |
getPropertyCSSValue(name) |
Returns the CSSValue object of the property value ( Contains cssText and cssValueType) |
getPropertyPriority(name) |
Whether the !important attribute is used |
getPropertyValue(name) |
Returns the string value of the given property |
removeProperty(name) |
Removes the given property from the style |
setProperty(name, value, priority) |
Set the given property to the corresponding value and add the priority |
##Attribute method | Description |
document.defaultView.getComputedStyle(dom, pseudo-element string) [ie not supported] | Return all calculated styles of the current element |
dom.currentStyle[ie support] | Return all calculated styles of the current element |
Operation style sheet
- document.styleSheets - all style sheets applied to the document
Properties (document.styleSheet[n]) | Description |
cssRules[ie not supported] | All style rules in a single style sheet |
rules[ie supported] | Same as above |
insertRule(rule,index)[ie not supported] | Add cssRules Insert the rule string at the specified position in the collection |
addRule(rule,index)[ie support] | Same as above |
##deleteRule (index)[ie not supported]
Delete the rule at the specified position in the cssRules collection |
| ##removeRule(index)[ie supported]
Same as above |
|
##document.styleSheets[n].cssRules/rules
Attribute
Description
|
| ##cssText[ie not supported]
String of the entire style rule
| selectorText | Style selector
| style | Specific style object
|
Size and offset |
Properties
Description
|
| offsetParent
Offset parent container
| getBoundingClientRect() | Get the actual position, width and height of the page element (return the attribute object)
| offsetWidth | Element width (visible content area + scroll bar + padding + border)
| offsetHeight | Element height (visual content area + scroll bar + padding + border)
| offsetLeft | Left distance from the adjacent parent
| offsetTop | The top distance from the adjacent parent
| clientWidth | Element width (visual content area + Padding)
| clientHeight | Element height (visible content area + padding)
| clientLeft | The distance between the padding edge and the border edge (left border)
| clientTop | The distance between the padding edge and the border edge (top border)
| scrollWidth | Element width (visible content area + scrolling content area + padding)
| scrollHeight | Element height (visible content area + scrolling content area + padding)
| scrollLeft | Hidden scroll width (width to be scrolled)
| scrollTop | Hidden scroll height (width to be scrolled)
|
Compatibility |
clientWidth/ There are browser differences between clientHeight and scrollWidth/scrollHeight
If you encounter any problems during the learning process or want to obtain learning resources, you are welcome to join the learning exchange group
The above is the detailed content of What are the commonly used DOM operations in js?. For more information, please follow other related articles on the PHP Chinese website!