Js traversal of subnode child elements

Source: Internet
Author: User

Js traversal of subnode child elements

Js traversal of subnode child elements

Method for attributes of subelements of Js nodes

// Delete all child nodes before adding a child node

Var usernameEle = document. getElementById ("username ");
Var childs = usernameEle. childNodes;
For (var I = childs. length-1; I> = 0; I --){
UsernameEle. removeChild (childs [I]);
}
Var username = document. createTextNode (obj. username );
UsernameEle. appendChild (username );


Attribute:NextSibling returns the next sibling node of the current node (read-only)
Previussibling returns the previous sibling node of this node (read-only)
ParentNode returns the parent node (read-only)
List of child nodes of the childNodes storage node (read-only)
NodeValue returns the node text (read/write)
Text returns the Text content of the node and its descendants (read/write)
NodeName: return the node name (read-only)

Attributes storage node attribute list (read-only) dataType returns the Data Type Definition of this node Definition in DTD or XML mode (read-only) Doctype specified file type node (read-only) documentElement returns the root element (read/write) of the document. firstChild returns the first child node (read-only) of the current node. Implementation returns the XMLDOMImplementation object. lastChild returns the last child node (read-only) of the current node) nodeType return node type (read-only) nodeTypedValue storage node value (read/write) ownerDocument returns the root document containing this node (read-only) parsed returns whether the node and Its subnodes have been resolved (read-only) Prefix returned namespace Prefix (read-only) preserveWhiteSpace specified whether to retain blank (read/write) the url returns the URL (read-only) XML of the recently loaded Xml document and the XML Representation of the node and its descendants (read-only)

Method:

GetElementsByTagName returns the set of elements with the specified name.
AppendChild adds a new sub-node to the current node, put it in the end of the sub-node, createElement creates an element node
CreateTextNode: Create a text node that includes the given data
RemoveChild deletes a specified subnode from the subnode list.
HasChildNodes: returns whether the current node has subnodes.

CloneNode returns the copy of the current node createAttribute create new attribute createCDATASection create CDATA segment including the given data createComment create a comment node createDocumentFragment create DocumentFragment object createEntityReference create EntityReference object createNode create a given type, name and namespace node createPorcessingInstruction create operation command node insertBefore insert sub-node Load import before the specified node XML document loadXML import specified string XML document replaceChild replace specified from the sub-node list the sub-node Save saves the XML file to the specified node selectNodes to match the specified node, return the matched node list selectSingleNode to match the specified node, the first matching node transformNode is returned. The node and its descendants are converted using the specified style table. transformNodeToObject: the node and its descendants are converted to objects using the specified style table.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.