


JavaScript node operations and DOMDocument properties and methods_javascript skills
Attributes:
1Attributes stores the node's attribute list (read-only)
2childNodes stores the node's child node list (read-only)
3dataType returns the data type of this node
4Definition in DTD or XML The definition of the node given by the mode (read-only)
5Doctype specifies the document type node (read-only)
6documentElement returns the root element of the document (readable and writable)
7firstChild returns the first child node of the current node (read-only)
8Implementation returns an XMLDOMImplementation object
9lastChild returns the last child node of the current node (read-only)
10nextSibling returns the next sibling node of the current node (read-only)
11nodeName returns the name of the node (read-only)
12nodeType returns the type of node (read-only)
13nodeTypedValue stores the node value (readable and writable)
14nodeValue returns the text of the node (readable and writable)
15ownerDocument returns the document containing this node Root document (read-only)
16parentNode Returns the parent node (read-only)
17Parsed Returns whether this node and its child nodes have been parsed (read-only)
18Prefix Returns the namespace prefix (read-only)
19preserveWhiteSpace Specifies whether to preserve white space (readable and writable)
20previousSibling Returns the previous sibling node of this node (read-only)
21Text Returns the text content of this node and its descendants (readable and writable)
22url Return The URL of the recently loaded XML document (read-only)
23Xml Returns the XML representation of the node and its descendants (read-only)
Method:
1appendChild Adds a new child node to the current node, placed at the end After the child node
2cloneNode returns a copy of the current node
3createAttribute creates a new attribute
4createCDATASection creates a CDATA segment including the given data
5createComment creates a comment node
6createDocumentFragment creates a DocumentFragment object
7createElement creates an element node
8createEntityReference creates an EntityReference object
9createNode creates a node of the given type, name and namespace
10createPorcessingInstruction creates an operation instruction node
11createTextNode creates a text node including the given data
12getElementsByTagName Returns a collection of elements with the specified name
13hasChildNodes Returns whether the current node has child nodes
14insertBefore Inserts a child node before the specified node
15Load Imports the XML document at the specified location
16loadXML Imports the XML of the specified string Document
17removeChild Delete the specified child node from the child node list
18replaceChild Replace the specified child node from the child node list
19Save Save the XML file to the specified node
20selectNodes Specify the node Match, and return a list of matching nodes
21selectSingleNode performs a specified match on the node, and returns the first matching node
22transformNode uses the specified style sheet to transform the node and its descendants
23transformNodeToObject uses the specified style sheet Convert node and its descendants to objects
************************************
DOM (documentation Object Model)
With the introduction of the concept of DOM (Document Object Model), this API has made HTML even more powerful, but some friends who are learning DHTML are still a little confused, just because the current manual is not very scientifically written, and it is written in letters
It’s divided, so it’s inconvenient to look up. In fact, the most important thing in DOM is to master the relationship between nodes (between node and node). If you want to learn the DOM in DHTML, don’t read all the attributes from beginning to end. And methods, do you have the "photographic memory" ability of Zhang Song during the Three Kingdoms? No, then let me analyze it:
In fact, what DOM teaches us is a hierarchical structure, which you can understand as a tree shape The structure, just like our directory, is a root directory. There are subdirectories under the root directory, and there are subdirectories under the subdirectories...
Root node:
DOM puts every object in the hierarchy It is called a node (NODE), taking HTML Hypertext Markup Language as an example: a root of the entire document is , which can be accessed in the DOM using
document.documentElement, which is the root of the entire node tree. Node (ROOT)
Child node:
A node in the general sense. The largest child node below the root node is the main document area
document.body
All text and HTML tags within the body area are nodes of the document, which are called text nodes and element nodes (or label nodes) respectively. Everyone knows that HTML is just text in the final analysis.
No matter Any webpage must be composed of these two nodes, and it can only be composed of these two nodes.
The relationship between nodes:
The relationship between nodes is also the most important joint in the DOM. How to correctly When referring to node objects, you must be clear about how each node of the node tree describes each other. In DHTML,
Javascript script uses a complete set of methods and attributes of each node object to describe other node objects.
Absolute reference of node:
Returns the root node of the document
document.documentElement
Returns the activated label node in the current document
document.activeElement
Returns the source node when the mouse is moved out
event.fromElement
Returns the source node that the mouse moves into
event.toElement
Returns the source node of the activated event
event.srcElement
Relative reference to the node: (Suppose the current node is node)
Returns the parent node
node.parentNode
node.parentElement
Returns the collection of child nodes (including text nodes and label nodes)
node.childNodes
Returns the collection of child label nodes
node.children
Returns the collection of child text nodes
node.textNodes
Returns the first child node
node.firstChild
Returns the last child node
node.lastChild
Return the next node of the same type
node.nextSibling
Return the previous node of the same type
node.previousSibling
Various operations of the node: (Suppose the current node is node)
Add a new label node Handle:
document.createElement(sNode) //The parameter is the label name of the node to be added, for example: newnode=document.createElement("div");
1. Add node:
Add child node :
node.appendChild(oNode) //oNode is a new node handle, for example: node.appendChild(newnode)
Apply label node
node.applyElment(oNode,sWhere)//oNode is Generate the newly added node handle, sWhere has two values: outside / inside, whether to add outside or inside the current node
Insert node
inode.insertBefore()
node.insertAdjacentElement()
node. replaceAdjacentText()
2. Modify node:
Remove node
node.remove()
node.removeChild()
node.removeNode()
Replace node
node. replaceChild()
node.replaceNode()
node.swapNode()
2. Copy node:
Return copy copy node reference
node.cloneNode(bAll)//bAll is a Boolean value , true/false Whether to clone all child nodes of the node
3. Whether the node information
contains a certain node
node.contains()
Whether there are child nodes
node.hasChildNodes()
****************************************************** ******
The following is the javascript operation xml

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

Usage: In JavaScript, the insertBefore() method is used to insert a new node in the DOM tree. This method requires two parameters: the new node to be inserted and the reference node (that is, the node where the new node will be inserted).

JavaScript is a programming language widely used in web development, while WebSocket is a network protocol used for real-time communication. Combining the powerful functions of the two, we can create an efficient real-time image processing system. This article will introduce how to implement this system using JavaScript and WebSocket, and provide specific code examples. First, we need to clarify the requirements and goals of the real-time image processing system. Suppose we have a camera device that can collect real-time image data
