3. DOM node.
Careful friends may have discovered that the <> and </> package letters are used to write HTML codes on them. Is this actually the case? The answer is no. The following is about the node type, otherwise you will make mistakes sometimes. For example, if you put the above code into the Mozilla firefox browser and you will know.
There are many node types in DOM. Here are some common node types in HTML documents (Note: XML is also a DOM tree structure).
1、DOCUMENT_NODE
(document) document root node type, the value of this enumeration type is 9.
2、ELEMENT_NODE
(element) The element node type, the value of this enumeration type is 1. The html, body, and div nodes above all belong to this type.
3、TEXT_NODE
(text) Text node type, the value of this enumeration type is 3. The text above, such as: tutorial of DHTML and javascript programming, belongs to this type.
(Note: A space may also be a text node)
Usually, it is more important to pay attention to text nodes. It is possible that one enters the carriage and one space is all text nodes. This will be encountered in the future. Of course, we have a way to deal with it. Don’t worry about it here, as we will also talk about it in the future.
4. Commonly used APIs for DOM
These commonly used APIs need to be recorded, and of course they will also be effective in non-IE browsers and are in line with w3c. These APIs will be used often in future programming. Just like the API provided by each programming platform, it must be written down frequently, saving time and improving programming efficiency. Only a few of the most commonly used ones are written, and other APIs will be written in future examples. From shallow to deep, from easy to difficult.
1. Get ELEMENT_NODE, element node
1) Method: (Id of the element), the return value is the reference of the node with the element. You can imagine the principle of this API: Like what we did above is to traverse each node (from the root to the node we need), this API can also be imagined as traversing from the root, querying each node (except blank nodes and empty nodes), and obtaining whether the id of the node is the specified ID, and if so, return this node (Note: In JS, arrays and objects are reference types), and return empty if not. We can write this code to help us understand. Here is an example of a simple traversal of elements in BODY.
[Ctrl+A Select all Note:Introducing external Js requires refreshing the page before execution]
Previous page12345Next pageRead the full text