JavaScript's Dom (Document object) Basic Syntax summary 1

Source: Internet
Author: User
Tags tagname

---restore content starts---

The HTML document can be said to be a collection of nodes, the DOM nodes are:

1). ELEMENT nodes:

2). Text node: Content that is presented to the user, such as JavaScript, DOM, CSS, and other text in <li>...</li>.

3). Attribute node: element properties, such as the <a> tag's link property href= "http://www.imooc.com".

1. Node Properties:

2. Traverse the node tree:

3. Dom Operation:

4.Getelementsbyname () method

// Syntax document.getelementsbyname (name)

Attention:

1) because the Name property in the document may not be unique, all getelementsbyname () methods return an array of elements, not an element.

2) and arrays similar also have the Length property, which can be accessed in the same way as an array of accesses, starting with 0.

//Examplefunction Getnum () {varMynode=document.getelementsbyname ("MYT")         ; alert (mynode.length);}</script><input name="MYT"Type="text"Value="1"><input name="MYT"Type="text"Value="2"><input name="MYT"Type="text"Value="3"><input name="MYT"Type="text"Value="4"><input name="MYT"Type="text"Value="5"><input name="MYT"Type="text"Value="6"><input type="Button"onclick="Getnum ()"Value="How many items are there? "/>//gets the name of the element that is MYT, and outputs the length of the element node that is obtained. 

5,getElementsByTagName () method: Returns the collection of node objects with the specified label name. The order in which elements are returned is their order in the document.

// Grammar document.getelementsbytagname (Tagname)

Description

1) tagname is the name of the label, such as P, A, IMG and other label names.

2) and arrays similar also have the Length property, which can be accessed in the same way as an array of accesses, so starting from 0.

//Examplefunction Getnum () {varMynode=document.getelementsbytagname ("input") ; alert (mynode.length);}</script><input type="text"Value="1"><input type="text"Value="2"><input type="text"Value="3"><input type="Button"onclick="Getnum ()"Value="See how many input tags are there? "/>//gets the input tag, and outputs the length of the element node that gets. 

JavaScript's Dom (Document object) Basic Syntax summary 1

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.