Home >Web Front-end >JS Tutorial >Detailed explanation of JS node knowledge_basic knowledge

Detailed explanation of JS node knowledge_basic knowledge

WBOY
WBOYOriginal
2016-05-16 18:35:28879browse

Pay attention to the capitalization and make sure there is no mistake.
Attributes:
Attributes stores the node’s attribute list (read-only)
childNodes stores the node’s child node list (read-only)
dataType Returns the data type of this node
Definition The definition of the node given in DTD or XML mode (read-only)
Doctype Specifies the document type node (read-only)
documentElement Returns the root element of the document ( Readable and writable)
firstChild returns the first child node of the current node (read-only)
Implementation returns an XMLDOMImplementation object
lastChild returns the last child node of the current node (read-only)
nextSibling returns the current node The next sibling node (read-only)
nodeName returns the name of the node (read-only)
nodeType returns the type of the node (read-only)
nodeTypedValue stores the node value (readable and writable)
nodeValue returns The text of the node (readable and writable)
ownerDocument returns the root document containing this node (read-only)
parentNode returns the parent node (read-only)
Parsed returns whether this node and its child nodes have been parsed ( Read-only)
Prefix Returns the namespace prefix (read-only)
preserveWhiteSpace Specifies whether to preserve white space (read-write)
previousSibling Returns the previous sibling node of this node (read-only)
Text Returns this The text content of the node and its descendants (readable and writable)
url Returns the URL of the recently loaded XML document (read-only)
Xml Returns the XML representation of the node and its descendants (read-only)
Methods:
appendChild adds a new child node to the current node and places it after the last child node
cloneNode returns a copy of the current node
createAttribute creates a new attribute
createCDATASection creates a include Given a CDATA segment of data
createComment creates a comment node
createDocumentFragment creates a DocumentFragment object
createElement creates an element node
createEntityReference creates an EntityReference object
createNode creates a given type, name and namespace Node
createPorcessingInstruction creates an operation instruction node
createTextNode creates a text node including the given data
getElementsByTagName returns a collection of elements with the specified name
hasChildNodes returns whether the current node has child nodes
insertBefore before the specified node Insert child node
Load Import the XML document at the specified location
loadXML Import the XML document with the specified string
removeChild Remove the specified child node from the child node list
replaceChild Replace the specified child node from the child node list The child node
Save saves the XML file to the specified node
selectNodes performs the specified matching on the node and returns the matching node list
selectSingleNode performs the specified matching on the node and returns the first matching node
transformNode uses the specified style sheet to transform the node and its descendants
transformNodeToObject uses the specified style sheet to transform the node and its descendants into objects
DOM (Document Object Model)
DOM (Document Object Model) concept With the launch of DHTML, 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 scientific, and it is divided by letters
, which is inconvenient to read. In fact, the most important thing in DOM is To master the relationship between nodes (between node andnode), if you want to learn the DOM in DHTML, don't read all the properties and methods from beginning to end. You have Zhang Song's "photographic memory" from the Three Kingdoms Do you have the ability to "forget"? No, then let me analyze it:
In fact, what DOM teaches us is a hierarchical structure. You can understand it as a tree structure, just like our directory, a root directory. There are subdirectories under the root directory, and there are subdirectories under the subdirectory
...

Root node: DOM calls every object in the hierarchy a node (NODE) , take 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 node (ROOT) of the entire node tree

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 how Such a webpage must be composed of these two nodes, and 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 quote it correctly When it comes 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");
, add node:
Append child node:
node.appendChild(oNode) //The new node handle for oNode, for example: node.appendChild(newnode)
Apply label node
node.applyElment(oNode,sWhere)//oNode for living 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 ()
, modify node:
Remove node
node.remove()
node.removeChild()
node.removeNode()
Replace node
node.replaceChild( )
node.replaceNode()
node.swapNode()
, copy node:
Return copy copy node reference
node.cloneNode(bAll)//bAll is a Boolean value, true / false Whether to clone all the child nodes of the node
, whether the node information
contains a certain node
node.contains()
whether there are child nodes
node.hasChildNodes()
*** *************************************************** **
The following is javascript operation xml

Statement:
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