Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

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?

+4
−0

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?

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

No, a node is not a branch... (8 comments)
No, a node is not a branch...
elgonzo‭ wrote over 2 years ago · edited over 2 years ago

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.

deleted user wrote over 2 years ago · edited over 2 years ago

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.

elgonzo‭ wrote over 2 years ago · edited over 2 years ago

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)

deleted user wrote over 2 years ago

Okay elgonzo‭ I have edited to clarify.

elgonzo‭ wrote over 2 years ago · edited over 2 years ago

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

deleted user wrote over 2 years ago

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‭ wrote over 2 years ago

Ah, alrighty then... If you wish, you can go ahead and self-answer...

deleted user wrote over 2 years ago

elgonzo‭ I know... In this particular scenario and at least as of this moment, I'd give the honor to an expert.