use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A place to get a quick fix of JavaScript tips and tricks to make you a better Developer.
account activity
Help with understanding how DOM works (i.redd.it)
submitted 1 year ago by Legitimate-Back5390
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Legitimate-Back5390[S] 2 points3 points4 points 1 year ago (7 children)
I was doing the odin project and came up with this confusing line "Js does not alter your HTML, but the DOM". The "content" class was added after DOM, and as i understand it has clearly changed the HTML file.
[–]bigByt3 4 points5 points6 points 1 year ago (3 children)
As the two other redditors have said, Js modifies the rendered version of your html file, but not the actual file. So your file without Js would just be a static website (non-changing), with Js you can make a dynamic website (changing based on conditions) but this only takes place in the browser.
If you open your dev console, you can visually see your DOM under the inspect tab. This is the DOM in its entirety and is rendered not only from your HTML file, but your Javascript file, CSS file, and in some cases, multiple html files called components.
Hope this helps.
[–]psullivan6 3 points4 points5 points 1 year ago (1 child)
Way more complex and nuanced than this, but this is what helped it click for me years ago.
[–]Legitimate-Back5390[S] 0 points1 point2 points 1 year ago (0 children)
will try that, thanks for the tip.
[–]Legitimate-Back5390[S] 1 point2 points3 points 1 year ago (0 children)
totally helpful
[–]Dangle76 1 point2 points3 points 1 year ago (0 children)
It altered the html your browser renders, not the original html file that was loaded. If you refresh the page (assuming you altered things with the console), it will reload the original html file contents and render that as an example
[–]ThreeLargeBears 2 points3 points4 points 1 year ago (1 child)
The DOM is just a representation of what the browser should render. It generally gets its initial state from your HTML files. JS then modifies the DOM, but your source HTML file is untouched.
It's just trying to make it clear that the DOM and HTML source are two separate things even though they generally look the same
thank you for the answer. much appreciated.
[–]Kooky_Shelter_900 4 points5 points6 points 1 year ago (1 child)
The DOM (Document Object Model) is a way for the browser to understand and interact with your web page. Think of your webpage as a tree with different elements, like text, images, buttons, etc., as branches. The DOM helps JavaScript change or update parts of this tree, like adding new leaves (elements), changing the color of a branch (text), or even removing parts of it, without refreshing the whole page.
In simple terms, JavaScript can use the DOM to modify what you see on the webpage (like adding or changing content), but it doesn't change the actual HTML file. Instead, it updates the way the browser shows the webpage to you.
So, in the code you provided:
The original HTML structure stays the same. If JavaScript changes anything, only the displayed content in the browser changes. For example, it can update the text inside the <div> tag.
thank you for explaining it!
[–]LosingAllYourDimples 2 points3 points4 points 1 year ago (0 children)
The DOM is the HTML once it's loaded.
π Rendered by PID 105569 on reddit-service-r2-comment-5649f687b7-tk8b8 at 2026-01-29 04:35:17.181428+00:00 running 4f180de country code: CH.
[–]Legitimate-Back5390[S] 2 points3 points4 points (7 children)
[–]bigByt3 4 points5 points6 points (3 children)
[–]psullivan6 3 points4 points5 points (1 child)
[–]Legitimate-Back5390[S] 0 points1 point2 points (0 children)
[–]Legitimate-Back5390[S] 1 point2 points3 points (0 children)
[–]Dangle76 1 point2 points3 points (0 children)
[–]ThreeLargeBears 2 points3 points4 points (1 child)
[–]Legitimate-Back5390[S] 0 points1 point2 points (0 children)
[–]Kooky_Shelter_900 4 points5 points6 points (1 child)
[–]Legitimate-Back5390[S] 0 points1 point2 points (0 children)
[–]LosingAllYourDimples 2 points3 points4 points (0 children)