Home > Web Front-end > JS Tutorial > body text

JavaScript node operations and DOMDocument properties and methods_javascript skills

WBOY
Release: 2016-05-16 19:07:23
Original
1119 people have browsed it

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 . To access the body tag, you should write in the script:
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

Copy code The code is as follows:


source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template