Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Comments on What are the types of DOM nodes?
Post
What are the types of DOM nodes?
If I am not mistaken any DOM "tree" node is actually a "branch", which would be an HTML element or perhaps a CSS pseudo-element, of course.
If that's true what are the different node types and especially what is TEXT_NODE here?
e.nodeType == Node.TEXT_NODE
mean in JavaScript?
A branch is a sub-tree in a tree, a node is just an element that can have child and/or parent relationships with other nodes (elements) in the tree. Such an element/node itself is not a branch. The relationship between nodes/elements is what is forming a tree/branch. Specifically a branch of/for/associated with a given node in a tree is the set of this given node and all other nodes that are descendants of the given node. The given node can serve as a representative of the branch, but it alone is not the branch.
what would a code such as
e.nodeType == Node.TEXT_NODE
mean in JavaScript?
This expression (==
is something you are surely familiar with if you ever worked through any tutorial covering the JS language fundamentals) will evaluate to either a false or true value depending on whether the value of "e.nodeType" is equal or unequal to the value of "Node.TEXT_NODE". Nothing more, nothing less.
DOM node types: https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
Skipping 2 deleted comments.
elgonzo either you don't understand my question or maliciously interpreting it or I did a crappy job in explaining what I am actually asking.
I meant to ask what is being compared ! and to get an idea about what is nodeType
.
Oh, my bad. Apologies (sincerly!). It's unfortunately quite easy to read your question that way, like "What does a == b
do?" instead of the "What is that a
thing there in the a==b
expression?" as you intended.
As the name of the "nodeType" property suggests, it contains a value that represents the type of the node/element (with the node object being assigned to the variable "e"). Node objects representing nodes/elements of different types will have different values in this property according to their actual node type. (https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType)
Okay elgonzo I have edited to clarify.
what is TEXT_NODE here
I already linked the documentation that explains what it is. Once more in case it got missed: https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
elgonzo I didn't miss it, it's just that I have already published a question which I don't find a good reason to delete and edited to prevent other people would understand as you did firstly...
elgonzo I know... In this particular scenario and at least as of this moment, I'd give the honor to an expert.

This community is part of the non-profit Codidact network. We have other communities too — take a look!
You can also join us in chat!
Want to advertise this community? Use our templates!
Like what we're doing? Support us! Donate
1 comment thread