Home  >  Article  >  Web Front-end  >  js traverse child node child element attachments and methods_javascript skills

js traverse child node child element attachments and methods_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:39:211378browse

Copy code The code is as follows:

// Delete all child nodes before adding child nodes

var usernameEle = document.getElementById("username");
var children = usernameEle.childNodes;
for(var i = children.length - 1; i >= 0; i--) {
usernameEle.removeChild(childs[i]);
}
var username = document.createTextNode(obj.username);
usernameEle.appendChild(username);

Properties:

nextSibling returns the next sibling node of the current node (read-only)
previousSibling returns the previous sibling node of this node (read-only)
parentNode returns the parent node (read-only)
childNodes stores the list of child nodes of the node (read-only)
nodeValue returns the text of the node (readable and writable)
Text returns the text content of this node and its descendants (readable and writable)
nodeName returns the name of the node (read-only)

Attributes stores the attribute list of the node (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 XMLDOMImplementation object
lastChild returns the last child node of the current node (read-only)
nodeType returns the type of node (read-only)
nodeTypedValue stores node value (readable and writable)
ownerDocument returns the root document containing this 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 whitespace (readable and writable)
url returns the URL of the recently loaded XML document (read-only)
Xml returns an XML representation of the node and its descendants (read-only)

Method:

getElementsByTagName returns a collection of elements with the specified name
appendChild adds a new child node to the current node and places it after the last child node
createElement creates an element node
createTextNode creates a text node containing the given data
removeChild removes the specified child node from the child node list
hasChildNodes returns whether the current node has child nodes

cloneNode returns a copy of the current node
createAttribute creates a new attribute
createCDATASection creates a CDATA section including the given data
createComment creates a comment node
createDocumentFragment creates a DocumentFragment object
createEntityReference creates EntityReference object
createNode creates a node of the given type, name and namespace
createPorcessingInstruction creates an operation instruction node
insertBefore inserts a child node before the specified node
Load imports the XML document at the specified location
loadXML imports the XML document of the specified string
replaceChild Replaces the specified child node from the child node list
Save Save the XML file to the specified node
selectNodes performs specified matching on nodes and returns a list of matching nodes
selectSingleNode performs a specified match on the node and returns the first matching node
transformNode transforms the node and its descendants using the specified stylesheet
transformNodeToObject Transforms a node and its descendants into objects using the specified stylesheet

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