In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what is the difference between node and element in DOM". In daily operation, I believe that many people have doubts about the difference between node and element in DOM. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the question of "what is the difference between node and element in DOM?" Next, please follow the editor to study!
The difference between node and element: 1, Node is a node, which contains different types of nodes, and Element is only one of the Node nodes; 2, Element inherits from Node, has Node methods, and expands many of its own unique methods.
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
We often use document.getElementById to get elements in DOM, and we also use childNodes to get child nodes. So what's the difference between Element and Node?
Do the nodes provided by Node and the nodes provided by Element always confuse Node and Eleme when learning jQuery?
On the left is Node/, and on the right is the relationship between ElementNode and Element. The relationship between Node and Element may be much clearer in terms of inheritance.
Element inherits from Node, has the method of Node, and extends many of its own unique methods at the same time.
In some methods of Element, there is a clear distinction between Node and Element
For example: childNodes and children, parentNode and parentElement and other methods.
For some methods of Node, the return value is Node, such as this section, comment nodes, etc., while some methods of Element, the return value must be Element.
A clear distinction between this point can also avoid a lot of low-level problems.
To put it simply, Node is a base class from which both Element,Text and Comment in DOM inherit.
In other words, Element,Text and Comment are three special kinds of Node, which are called ELEMENT_NODE
TEXT_NODE and COMMENT_NODE.
So the element on html that we usually use, that is, Element, is a Node of type ELEMENT_NODE.
Summary:
Node is a node, which contains different types of nodes, and Element is just one of the Node nodes.
Element inherits from Node and can call the method of Node.
To add methods to all DOM elements, you only need to contaminate the prototype chain of Node or Element.
Node here refers to the DOM node, which includes our most common element nodes, such as div/p/span. In addition, nodes such as Document/Comment are included.
The type of a node can be seen through its nodeType type, and the specific type can be seen in the following figure:
At this point, the study on "what is the difference between node and element in DOM" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.