[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.