Js traversal subnode subelement attributes and methods, js ideas

Source: Internet
Author: User

Js traversal subnode subelement attributes and methods, js ideas

Copy codeThe Code is as follows:
// 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)

Attribute list of the Attributes storage node (read-only)
DataType returns the Data Type of this node
Definition defines nodes in DTD or XML mode (read-only)
Doctype specifies the file type node (read-only)
DocumentElement returns the root element of the document (read/write)
FirstChild returns the first child node of the current node (read-only)
Implementation returns the XMLDOMImplementation object
LastChild returns the last child node of the current node (read-only)
NodeType return node type (read-only)
NodeTypedValue stores node values (read/write)
OwnerDocument returns the root document containing this node (read-only)
Parsed: returns whether the node and Its subnodes have been Parsed (read-only)
Prefix returns the namespace Prefix (read-only)
PreserveWhiteSpace specifies whether to retain white space (read/write)
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)

Method:

GetElementsByTagName returns the set of elements with the specified name.
AppendChild adds a new subnode to the current node, which is placed after the last subnode
CreateElement: Create 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
CreateCDATASection create CDATA segments that contain the given data
CreateComment create a comment Node
CreateDocumentFragment create a DocumentFragment object
CreateEntityReference: Create an EntityReference object
CreateNode creates nodes of the given type, name, and namespace.
CreatePorcessingInstruction
InsertBefore inserts a subnode before a specified Node
Load import the XML document at the specified position
LoadXML import the XML document of the specified string
ReplaceChild replaces the specified child node from the child node list
Save the XML file to the specified Node
SelectNodes matches the specified node and returns the list of matched nodes.
SelectSingleNode matches the specified node and returns the first matching node.
TransformNode converts nodes and their descendants using the specified style table.
TransformNodeToObject: Use the specified style sheet to convert nodes and their descendants to objects.


Js traverses all elements on the current page and obtains the elements with the title attribute.

Function getHasTitles (parentNode) {var allNodes = parentNode. getElementsByTagName ('*'); var length = allNodes. length; var I; var hasTitles = []; var node; for (I = 0; I <length; I ++) {node = allNodes [I]; if (node. title) {hasTitles. push (node) ;}} return hasTitles;} var hasTitles = getHasTitles (document );
Jquery gets all elements
$ ("*")


How does js traverse elements in a webpage?

I think the reason is: Your code above should be in onload (). When the page is loaded, for (var I = 0; I <list. length; I ++) {list [I]. onclick = function () {temp [I]

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.