Javascriptdom Programming Art _ Learning Notes _ Knowledge point DOM

Source: Internet
Author: User

Chapter III   getElementByIdReturns an object that corresponds to the element node that has the given ID attribute value. document.getElementById (ID) below an example:
1 document.getElementById ("purchases")

getElementsByTagNamemethod returns an array of objects, each corresponding to an element in the document that has a given label. Element.getelementsbytagname (TAG) below an example:
1 document.getelementsbytagname ("li")2 alert (document.getelementsbytagname ("Li"). length);

GetelementsbyclassnameThe HTML5 DOM is new, allowing us to access the element through the class name in the Class attribute. Getelementsbyclassname (Class) below an example:
1 document.getelementsbyclassname ("Sale")

getattributeis a function. It has only one parameter--the name of the property you intend to query Object.getattribute (attribute) below an example:
1 var paras = document.getelementsbytagname ("P"); 2  for (var i=0;i < paras.length;i++) {3     alert (Paras[i].getattribute ("title")); 4 }

SetAttributeIt allows us to make changes to the value of the attribute node. Can only be used for element nodes Object.setattribute (attribute,value) below an example:
1 var shopping = document.getElementById ("purchases"); 2 shopping.setattribute ("title", "a list of goods");

Fourth Chapter ChildNodesThe Element.childnodes property can be used to get all the elements of any one element, which is an array containing all the child elements of this element, in the following example:
1 var body_element = Document.getelementbytagname ("body") [0]; 2 Body_element.childnodes 3 document.getelementbytagname ("body") [0].childnodes

NodeTypeproperty, each node has a NodeType property. This property allows us to know which node we are dealing with, with a total of 12 desirable values for the Node.nodetypenodetype attribute, but only 3 of them are of practical value. The NodeType attribute value of the element node is 1. The NodeType property value of the attribute node is 2. The NodeType property value of the text node is 3. Here's an example:
1 alert (body_element.nodetype);

NodeValueproperty, which is used to get (and set) the value of a node. Node.nodevalue The following example:
1 alert (decription.nodevalue); 2 alert (decription.childnodes[0].nodevalue);

FirstChildProperties, and LastChildThe FirstChild property represents the first element of the ChildNodes array LastChild property represents the last element of the childnodes array

Javascriptdom Programming Art _ Learning Notes _ Knowledge point DOM

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.