JavaScript DOM Basic operations
1.DOM (Document Object model)
2. Node:
- Documentation node: Document
- ELEMENT nodes: HTML, head, body, title, meta, H1, p, etc.
- Attribute node: attr
- Text-node: text
2.1 Node Acquisition
- Documen.getelementbyid ("Element ID")//Returns the element containing the ID
- Document.getelementsbyname ("element name attribute")//Returns the collection with the specified name element
- document.getElementsByTagName ("element tag")//Returns a collection of specified elements
2.2 Attribute node processing
- Elementnode. Hasattribute ("Attrname")//detects if the selected element has a Attrname attribute eg:documen.getElementById ("Nav"). Hasattribute ("class")
- Elementnode. getattribute ("Attrname")//Gets the value of the element Attrname property
- Elementnode. SetAttribute ("Attrname", "attrValue")//Set properties, create or change element property values
- Elementnode. RemoveAttribute ("Attrname")//Remove attributes
- Note: When getting properties and removing attributes, use the Hasattribute () method to determine whether this property exists
2.3 Text Node processing
- Get and set text node properties through the innerHTML property
- Documen.getelementbyid ("Content"). Innerhtml= "<p>hello!</p>"
3 traversing the DOM
- Parent node. FirstChild//Gets the first child node of the element
- Parent node. LastChild//Gets the last child node of the element
- Parent node. Childnode//Get element child node list
- Child nodes. parentnode//Get a known node parent node
- Sibling node. previoussibling//Get the previous node of a known node
- Brother node. nextSibling//Get a node after a known node
4. Node operation
JavaScript DOM Basic operations