[Javascript Summary] javascript DOM programming and javascriptdom Programming

Source: Internet
Author: User

[Javascript Summary] javascript DOM programming and javascriptdom Programming
Access HTML elements

  • Access HTML elements by ID.
  • Access HTML elements based on node relationships.

Commonly used

Document. getElementById ("idVal"); // get the node whose ID is named idVal.
Document. getElementsByName ("name"); // The returned tag set is name.
Document. getElementsByTagName ("input") // return the set of all input tags
Addition, deletion, modification, query, and addition of DOM:

1. Create a node

Document. createElement (Tag) // The Tag must be a valid HTML Tag name.

Copy a node

Node cloneNode (boolean deep) // when deep is set to true, it means that when the current Node is copied, it also copies all the content in it. Otherwise, it means copying herself.

Add Node

AppendChild (Node newNode) // Add it as insertBefore (Node newNode, Node refNode) // Add it to the front of the refNode Node replaceChild (Node newNode, Node oldNode) // Replace the Node
Delete:

Delete a node

RemoveChild (oldNode) // Delete the oldNode node parameter so that the object can be a number
Change

Obtain the element to be modified and then modify innerHTML or its value.

Query

Access Node

Document. getElementById ("id"); // obtain the element whose id is id.

You can also use the sibling relationship between nodes.

Access Form

Document. getElementById ('form'). elements [0] // The first element in the form is returned. Document. getElementById ('form'). elements ['pass'] // return the form element whose name is pass.

Access list box

Document. getElementById ('select'). options [n] // select the nth element in the list.

Access Table Elements

Document. getElementById ('table'). row [1]. cells [2] // return the third grid of row 2nd of the 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.