<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: webdev1801</title>
    <description>The latest articles on DEV Community by webdev1801 (@web_dev2204).</description>
    <link>https://dev.to/web_dev2204</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1132319%2Fa0996783-2f8d-45c9-a02d-2cd382815fcd.png</url>
      <title>DEV Community: webdev1801</title>
      <link>https://dev.to/web_dev2204</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/web_dev2204"/>
    <language>en</language>
    <item>
      <title>Exploring the Fundamentals of Browser Components and the DOM</title>
      <dc:creator>webdev1801</dc:creator>
      <pubDate>Fri, 04 Aug 2023 13:40:21 +0000</pubDate>
      <link>https://dev.to/web_dev2204/exploring-the-fundamentals-of-browser-components-and-the-dom-jhg</link>
      <guid>https://dev.to/web_dev2204/exploring-the-fundamentals-of-browser-components-and-the-dom-jhg</guid>
      <description>&lt;p&gt;In preparing to engage with &lt;strong&gt;DOM&lt;/strong&gt; projects, it's essential to establish a foundational understanding of the core components that shape our web browsing experience. &lt;/p&gt;

&lt;p&gt;Let's take a moment to distinguish between the key entities within the browser environment: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the Window,&lt;/li&gt;
&lt;li&gt; Navigator&lt;/li&gt;
&lt;li&gt;and Document. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--V5qZ5ZLO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b5unwj4vj6krfsyu7sht.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--V5qZ5ZLO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b5unwj4vj6krfsyu7sht.png" alt="Image description" width="664" height="444"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;window&lt;/strong&gt; is the browser tab that a web page is loaded into; this is represented in JavaScript by the &lt;strong&gt;Window object&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Using methods available on this &lt;em&gt;object&lt;/em&gt; you can do things like return the window's size (see &lt;strong&gt;Window.innerWidth&lt;/strong&gt; and &lt;strong&gt;Window.innerHeight&lt;/strong&gt;), manipulate the document loaded into that window, store data specific to that document on the client-side (for example using a local database or other storage mechanism), attach an event handler to the current window, and more.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;navigator&lt;/strong&gt; represents the state and identity of the browser (i.e. the user-agent) as it exists on the web. In JavaScript, this is represented by the &lt;strong&gt;Navigator object&lt;/strong&gt;. You can use this &lt;em&gt;object&lt;/em&gt; to retrieve things like the user's preferred language, a media stream from the user's webcam, etc.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;document&lt;/strong&gt; (represented by the &lt;strong&gt;DOM&lt;/strong&gt; in browsers) is the actual page loaded into the window, and is represented in JavaScript by the Document object. You can use this object to return and manipulate information on the HTML and CSS that comprises the document, for example get a reference to an element in the DOM, change its text content, apply new styles to it, create new elements and add them to the current element as children, or even delete it altogether.&lt;/p&gt;

&lt;p&gt;Let's take an example of a very simple page containing a  element inside which you can find an image, and a paragraph with a link inside. The HTML source code looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!doctype html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en-US"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"utf-8"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Simple DOM example&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;section&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt;
        &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"dinosaur.png"&lt;/span&gt;
        &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"A red Tyrannosaurus Rex: A two legged dinosaur standing upright like a human, with small arms, and a large head with lots of sharp teeth."&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;
        Here we will add a link to the
        &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://www.mozilla.org/"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Mozilla homepage&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/section&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;DOM&lt;/strong&gt; on the other hand looks like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--at7idey9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/enrl9i9lhwitbjgp5fr8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--at7idey9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/enrl9i9lhwitbjgp5fr8.png" alt="Image description" width="717" height="396"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each entry in the tree is called a &lt;strong&gt;node&lt;/strong&gt;. You can see in the diagram above that some nodes represent elements (identified as HTML, HEAD, META and so on) and others represent text (identified as #text). There are other types of nodes as well, but these are the main ones you'll encounter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Nodes&lt;/strong&gt; are also referred to by their position in the tree relative to other nodes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Root node&lt;/strong&gt;: The top node in the tree, which in the case of HTML is always the HTML node &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Child node&lt;/strong&gt;: A node directly inside another node. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, IMG is a child of SECTION in the above example.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Descendant node&lt;/strong&gt;: A node anywhere inside another node. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, IMG is a child of SECTION in the above example, and it is also a descendant. IMG is not a child of BODY, as it is two levels below it in the tree, but it is a descendant of BODY.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Parent node&lt;/strong&gt;: A node which has another node inside it. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, BODY is the parent node of SECTION in the above example.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Sibling nodes&lt;/strong&gt;: Nodes that sit on the same level in the DOM tree. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, IMG and P are siblings in the above example.&lt;/p&gt;

&lt;p&gt;It is useful to familiarize yourself with this terminology before working with the DOM, as a number of the code terms you'll come across make use of them. You may have also come across them if you have studied CSS (e.g. descendant selector, child selector).&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>html</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
