Detailed explanation of javascriptAPI and case analysis (1)

Source: Internet
Author: User
Method return type description nodeNameString node name nodeValueString node value nodeTypeNumber node type constant value firstChildNode points to the first node in the childNodes list lastChildNode points to the last node childN in the childNodes list...
Method Return type Description
NodeName String Node name
NodeValue String Node Value
NodeType Number Type constant value of a node
FirstChild Node Point to the first node in the childNodes list
 
LastChild Node Point to the last node in the childNodes list
ChildNodes NodeList List of all child nodes
Previussibling Node Indicates a forward sibling node. If this node is the first sibling node
Point, then the value is null
NextSibling Node Point to the next sibling node. If this node is the last sibling node
Point, then the value is null
HasChildNodes () Boolean Returns true if childNodes contains one or more nodes.
Attributes NamedNodeMap Contains Attr objects that represent the characteristics of an Element. It is only used for Element
Node
AppendChild (Node)
 
Node SetNodeAdd to the end of childNodes
RemoveChild (Node)
 
Node Delete from childNodesNode
ReplaceChild (Newnode,Oldnode) Node In childNodesOldnodeReplaceNewnode
 

1 getElementById ()
Note:
1. query the element with the given ID attribute value and return the Element Node of the element. It is also called an element object.
2. Because the id value in an html page is unique, the return value is unique. Therefore, the method name is getElementById () instead of getElementsById ()
3. This method can only be used for document objects, similar to the static keyword of java.
Case:
Var inputDom = document. getElementById ("uname ")
// The attribute value of the current dom object
 
Alert (inputDom. type + inputDom. value + inputDom. id );
// Element node name label name value is null Element Node Type value 1
Alert (inputDom. nodeName + inputDom. nodeType + inputDom. nodeValue );
2. getElementsByName ()
2.1 note:
1. Search for all elements of the given name attribute. This method returns a node set, also known as an object set.
2. This set can be treated as an array. The value of the length attribute indicates the number of sets.
3. Because name cannot uniquely identify an element on an html page, the method name is getElementsByName instead of getElementByName.
Example:



GetElementsByName.html
 






 



User Name



What are your favorite spring festival programs?


111
222
333
444
555
666









Related Article

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.