1.DOM: Document Object Model DOM (Document Object Model) defines a standard method for accessing and processing HTML documents. DOM presents HTML documents as a tree structure (node tree) with elements, attributes, and text.
2. Some commonly used attributes of DOM
2.1 Get elements by ID
(1) Grammar:
(2) Function: ID is a person’s ID card. We can find the tag by looking for its ID, and then perform corresponding operations.
(3) Note: Don’t forget to write the document!
2.2 innerHTML attribute
(1) Grammar:
(2) Function: Mainly to obtain or replace the content in the tag
(3) Example:
JavaScript is a simple object-based, event-driven scripting language. It is embedded in HTML documents and is interpreted and executed by the browser. It produces dynamic display effects on web pages and implements interactive functions with users.
(4) Note: Object is the element object obtained, such as the element obtained through document.getElementById("ID").
2.3 Change HTML style
(1) Grammar:
(2) Function: Used to modify HTML style
(3) Example:
JavaScript enables web pages to display dynamic effects and implement interactive functions with users.
(4) Note: There are many styles of property, such as color, height, etc., which can be modified using this method. Don’t forget to add a semicolon after the property.
2.4 Showing and hiding (display attribute)
(1) Grammar:
Object.style.display=value
(2) Function: Showing and hiding are often seen on web pages, which is achieved using the display attribute
(3) Example:
2.5 className attribute
(1) Grammar:
(3) Example:
JavaScript enables web pages to display dynamic effects and implement interactive functions with users.
JavaScript enables web pages to display dynamic effects and implement interactive functions with users.