<?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: horlartundhey</title>
    <description>The latest articles on DEV Community by horlartundhey (@horlartundhey).</description>
    <link>https://dev.to/horlartundhey</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F894489%2F18de470f-3167-4c13-8e1e-ffc794aea4b7.PNG</url>
      <title>DEV Community: horlartundhey</title>
      <link>https://dev.to/horlartundhey</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/horlartundhey"/>
    <language>en</language>
    <item>
      <title>Week 3 at DMI — When Linux Stopped Being Theory</title>
      <dc:creator>horlartundhey</dc:creator>
      <pubDate>Mon, 20 Jul 2026 16:04:19 +0000</pubDate>
      <link>https://dev.to/horlartundhey/week-3-at-dmi-when-linux-stopped-being-theory-1cl5</link>
      <guid>https://dev.to/horlartundhey/week-3-at-dmi-when-linux-stopped-being-theory-1cl5</guid>
      <description>&lt;p&gt;Week 3 of DevOps Micro Internship was the week Linux stopped being something I read about and became something I broke, diagnosed, and fixed on a real Ubuntu VM.&lt;/p&gt;

&lt;p&gt;It started with spinning up an AWS Free Tier account and provisioning the EC2 instance I'd be operating on for the rest of the week. From there, I deployed two real applications through Nginx: a React app built with Node.js and npm, and a personal portfolio site, EpicReads. Both drills covered the same core loop — install the runtime, clone the code, build it, move the build into Nginx's web root, and configure the server block to serve it correctly. Small details mattered more than I expected: file permissions, the right root path, and a working reverse-proxy config were the difference between a blank page and a live site.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ficpu6gc0vi2z0vodc831.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ficpu6gc0vi2z0vodc831.png" alt="Linux" width="635" height="249"&gt;&lt;/a&gt;&lt;br&gt;
The most valuable part of the week was the &lt;strong&gt;Production Maintenance Drill&lt;/strong&gt;, where I deliberately broke things in order to learn how to recover them. In one simulation, two semicolons went missing from my Nginx config. &lt;code&gt;nginx -t&lt;/code&gt; caught the syntax error before I restarted anything, I restored the missing semicolons, re-validated, and restarted the service — confirming recovery with an external &lt;code&gt;curl -I&lt;/code&gt; check for a clean &lt;code&gt;200 OK&lt;/code&gt;. In a second simulation, the entire web root was emptied out, and the app started returning &lt;code&gt;500&lt;/code&gt;s even though Nginx itself stayed healthy. Because I'd backed up the deployment beforehand, recovery was just restoring the backup and re-verifying — a small preview of why atomic, versioned deployments matter in real production systems.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbq8tyiojc5l4g4949uvs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbq8tyiojc5l4g4949uvs.png" alt="Bash Scripting" width="800" height="542"&gt;&lt;/a&gt;&lt;br&gt;
Alongside that, I worked through Bash scripting fundamentals — variables, arrays, loops, conditionals, and functions — building up to a small automation script. That groundwork paid off immediately in the week's capstone: building an &lt;strong&gt;AI-assisted Linux health-check skill&lt;/strong&gt; with Claude Code. I wrote a triage script, wired it into a Claude Code skill, then simulated a real incident (nginx stopped, port 80 down, HTTP checks failing). The skill correctly gathered evidence and diagnosed the cause from the logs — but it was restricted to read-only analysis by design. Per the project's safety rules, only I, the human, could approve and run the actual fix (&lt;code&gt;sudo systemctl start nginx&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;That distinction — AI that investigates and recommends, but doesn't execute — is the same "guardrails, not autopilot" lesson from Week 2, and it's the one I keep relearning: the tooling should make me faster at making decisions, not replace the decision.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;P.S. This post is a part of DevOps Micro Internship with Agentic AI Cohort-3 by &lt;a href="https://www.linkedin.com/in/pravin-mishra-aws-trainer/" rel="noopener noreferrer"&gt;Pravin Mishra&lt;/a&gt;. You can start your DevOps journey by joining the DMI waiting list: &lt;a href="https://forms.gle/3hvrWJBDzsDeJoPs6" rel="noopener noreferrer"&gt;https://forms.gle/3hvrWJBDzsDeJoPs6&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  DMIByPravinMishra
&lt;/h1&gt;

&lt;p&gt;You can follow &lt;a href="https://dmi.pravinmishra.com/s/horlartundhey.html" rel="noopener noreferrer"&gt;my graded progress&lt;/a&gt; throughout the cohort.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Week 0 at DMI: Relearning the Internet From First Principles</title>
      <dc:creator>horlartundhey</dc:creator>
      <pubDate>Mon, 20 Jul 2026 15:59:53 +0000</pubDate>
      <link>https://dev.to/horlartundhey/week-0-at-dmi-relearning-the-internet-from-first-principles-588n</link>
      <guid>https://dev.to/horlartundhey/week-0-at-dmi-relearning-the-internet-from-first-principles-588n</guid>
      <description>&lt;p&gt;Before I touched a single cloud console, DevOps Micro Internship Cohort 3 sent me back to the internet's plumbing — and it turned out I needed the refresher more than I expected.&lt;/p&gt;

&lt;p&gt;Task one asked me to use ChatGPT as a learning assistant, prompting it to explain "What is a protocol in networking?" with a real-life example. The answer stuck with me in the simplest possible way: a protocol is just a set of rules devices agree on before they talk, the same way two people agree on a shared language before a conversation makes sense. That framing carried me through everything else that week.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftsphwunhduvcttjwhc9p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftsphwunhduvcttjwhc9p.png" alt="Task one using ChatGPT as a learning assistant" width="799" height="440"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The core exercise put me in the shoes of a friend launching an online bookstore called &lt;strong&gt;EpicReads&lt;/strong&gt;, hosted on a server in Finland, and asked me to explain to him how someone on the other side of the world would actually reach his site. Walking through packet switching, IP addressing, TCP/IP, and HTTP/HTTPS forced me to stop treating "the internet" as a black box. A request doesn't travel as one block of data — it's broken into packets, routed independently, addressed to a specific IP, and reassembled at the other end, all wrapped in TCP/IP's reliability guarantees and delivered over HTTP or HTTPS.&lt;/p&gt;

&lt;p&gt;From there, I mapped out two-tier and three-tier application architecture (frontend/database vs. frontend/backend/database), which made it obvious why EpicReads would eventually need a backend layer once it outgrew a simple storefront. Then came DNS: understanding that &lt;code&gt;epicreads.com&lt;/code&gt; is really just a friendly alias for &lt;code&gt;52.172.142.222&lt;/code&gt;, resolved through an &lt;strong&gt;A record&lt;/strong&gt;, was the moment the whole stack finally clicked together — domain name, DNS, IP, and server all pointing at the same thing from different angles.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fd0oc3o2ietm2k3x35qp2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fd0oc3o2ietm2k3x35qp2.png" alt="mapped out two-tier and three-tier application architecture" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The hardest part wasn't any single concept — it was holding TCP/IP, DNS, and architecture in my head at the same time as one connected flow instead of four separate facts. That's the habit I'm carrying into the rest of the internship: build the mental model first, then layer in the tools.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;P.S. This post is a part of DevOps Micro Internship with Agentic AI Cohort-3 by &lt;a href="https://www.linkedin.com/in/pravin-mishra-aws-trainer/" rel="noopener noreferrer"&gt;Pravin Mishra&lt;/a&gt;. You can start your DevOps journey by joining the DMI waiting list: &lt;a href="https://forms.gle/3hvrWJBDzsDeJoPs6" rel="noopener noreferrer"&gt;https://forms.gle/3hvrWJBDzsDeJoPs6&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  DMIByPravinMishra
&lt;/h1&gt;

&lt;p&gt;You can follow &lt;a href="https://dmi.pravinmishra.com/s/horlartundhey.html" rel="noopener noreferrer"&gt;my graded progress&lt;/a&gt; throughout the cohort.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Week 2 of my reflections from the DevOps Micro Internship: Guardrails, Not Autopilot</title>
      <dc:creator>horlartundhey</dc:creator>
      <pubDate>Fri, 10 Jul 2026 13:42:20 +0000</pubDate>
      <link>https://dev.to/horlartundhey/week-2-of-my-reflections-from-the-devops-micro-internship-guardrails-not-autopilot-1nje</link>
      <guid>https://dev.to/horlartundhey/week-2-of-my-reflections-from-the-devops-micro-internship-guardrails-not-autopilot-1nje</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fd0z4n2m3te06nhlzfr4v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fd0z4n2m3te06nhlzfr4v.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Learning to trust an AI coding agent with real infrastructure, one permission at a time&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Going into Week 2 of the DMI DevOps Micro Internship, I assumed I already understood what an AI coding assistant does: you type a prompt, it writes some code, you review it. What I actually learned this week is that Claude Code isn't a text generator you talk to; it's an &lt;strong&gt;agent&lt;/strong&gt; operating inside a system of guardrails, and understanding those guardrails turned out to be the real curriculum.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Biggest technical insight I got this week
&lt;/h2&gt;

&lt;p&gt;The concept that reframed everything for me was the &lt;strong&gt;agentic loop&lt;/strong&gt;: read context, plan, call a tool, observe the result, decide the next step, repeat until done. That loop is powerful, but it's only &lt;em&gt;safe&lt;/em&gt; because of what wraps around it.&lt;/p&gt;

&lt;p&gt;In the project I worked on, &lt;code&gt;CLAUDE.md&lt;/code&gt; tells the agent upfront that the site is pure HTML/CSS with no JavaScript and no build step, so it doesn't waste a turn inventing a bundler or npm scripts that were never there. Layered on top of that are &lt;strong&gt;skills&lt;/strong&gt;: reusable slash commands like &lt;code&gt;/scaffold-terraform&lt;/code&gt; and &lt;code&gt;/tf-plan&lt;/code&gt; that turn a long, easy-to-forget prompt into a single, repeatable action, each with its own declared &lt;code&gt;allowed-tools&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That's where tool restrictions stopped being an abstract "best practice" and became something I could point to. The &lt;code&gt;tf-plan&lt;/code&gt; skill is scoped to &lt;code&gt;Bash, Read, Grep&lt;/code&gt;, deliberately &lt;strong&gt;no &lt;code&gt;Write&lt;/code&gt;&lt;/strong&gt;, because a plan should only &lt;em&gt;observe&lt;/em&gt; infrastructure, never change it. &lt;code&gt;settings.json&lt;/code&gt; reinforces the same philosophy at the project level: it explicitly allows read-only Terraform and AWS calls (&lt;code&gt;terraform plan&lt;/code&gt;, &lt;code&gt;aws s3 ls&lt;/code&gt;, &lt;code&gt;aws sts get-caller-identity&lt;/code&gt;) and explicitly denies destructive ones (&lt;code&gt;rm -rf *&lt;/code&gt;, &lt;code&gt;aws iam *&lt;/code&gt;). Permissions, I realized, aren't bureaucracy bolted onto AI, they're the actual mechanism that makes it safe to hand an agent something as consequential as real cloud infrastructure.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Biggest insight I got about myself this week
&lt;/h2&gt;

&lt;p&gt;I learn better while doing a video guide that helps people, which surprisingly makes the learning and doing more interesting.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. My biggest weakness or loop I noticed
&lt;/h2&gt;

&lt;p&gt;The loop I kept catching myself in was trusting documentation over the actual state of the repo. This project's own &lt;code&gt;CLAUDE.md&lt;/code&gt; includes a candid note that earlier commits referenced &lt;code&gt;.claude/skills/&lt;/code&gt;, a GitHub Actions workflow, and a &lt;code&gt;terraform/&lt;/code&gt; directory, but those were later deleted from the working tree, meaning the "documented" pipeline was aspirational, not real. More than once I found myself reasoning about a file as if it existed because a description said it should, instead of running &lt;code&gt;git status&lt;/code&gt; or listing the directory first. It's a small habit gap, but in DevOps, where "what's documented" and "what's actually deployed" can quietly diverge, it's exactly the kind of gap that causes real incidents.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. One system I will implement this week
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Before running any skill or command that touches infrastructure, like &lt;code&gt;/scaffold-terraform&lt;/code&gt; or &lt;code&gt;/tf-plan&lt;/code&gt;, I will first run &lt;code&gt;git status&lt;/code&gt; and check the relevant directory to confirm what actually exists on disk, rather than trusting &lt;code&gt;CLAUDE.md&lt;/code&gt; or a skill description alone. I'll do this at the start of &lt;em&gt;every&lt;/em&gt; task, not just once per session, so I stop building on assumptions about files that were deleted, renamed, or never committed in the first place.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  5. What I learned about Agentic AI and DevOps
&lt;/h2&gt;

&lt;p&gt;Before this internship, "AI" meant a chat window that answered questions. This week reframed it as an &lt;strong&gt;operator with guardrails&lt;/strong&gt;. An agentic AI can follow a structured workflow end-to-end, scaffold Terraform, run a plan, hand the output to a &lt;code&gt;security-auditor&lt;/code&gt; or &lt;code&gt;cost-optimizer&lt;/code&gt; subagent, and only then wait for a human to approve &lt;code&gt;tf-apply&lt;/code&gt;, instead of producing a single disconnected answer.&lt;/p&gt;

&lt;p&gt;What stood out most is that the safety doesn't come from the model being well-behaved; it comes from &lt;em&gt;design&lt;/em&gt;. &lt;code&gt;tf-plan&lt;/code&gt; physically cannot write files. Destructive commands are denied at the settings level, not just discouraged in a prompt. Hooks fire before and after every shell command to check and log what's happening, whether the model "intended" to be careful or not. Reusable skills cut the repetitive typing, which is nice, but the real lesson is that DevOps engineers now have to design two things at once: the automation, and the control layer that keeps it honest. Human review before &lt;code&gt;apply&lt;/code&gt; isn't a leftover step from the pre-AI era. It's still the last line of defense.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. My Week 2 highlight
&lt;/h2&gt;

&lt;p&gt;Highlight of this week will be understanding and actually creating &lt;code&gt;skills&lt;/code&gt; and &lt;code&gt;sub-agents&lt;/code&gt;, using &lt;code&gt;claude.md&lt;/code&gt; as a guide to make sure my agent has the correct context to work with. &lt;/p&gt;

&lt;p&gt;I had a bit of an issue with Terraform, but this made me understand the flow better. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;This is Week 2 of my reflections from the DevOps Micro Internship. If you're on a similar path, I'd love to hear what clicked for you this week too.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>devops</category>
      <category>claude</category>
    </item>
    <item>
      <title>Introduction to the Document Object Model(DOM): The Foundation of Frontend Development</title>
      <dc:creator>horlartundhey</dc:creator>
      <pubDate>Thu, 12 Jun 2025 13:32:11 +0000</pubDate>
      <link>https://dev.to/horlartundhey/introduction-to-the-document-object-modeldom-the-foundation-of-frontend-development-3fim</link>
      <guid>https://dev.to/horlartundhey/introduction-to-the-document-object-modeldom-the-foundation-of-frontend-development-3fim</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fds2ns7asvgke8dnjw83g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fds2ns7asvgke8dnjw83g.png" alt="Image description" width="800" height="1200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What's this article about?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;What is the DOM?&lt;/li&gt;
&lt;li&gt;Why is the DOM Important in Frontend Development?&lt;/li&gt;
&lt;li&gt;Understanding the DOM Tree Structure&lt;/li&gt;
&lt;li&gt;Interacting with the DOM using JavaScript&lt;/li&gt;
&lt;li&gt;Events and the DOM&lt;/li&gt;
&lt;li&gt;Common Mistakes Beginners Make with the DOM&lt;/li&gt;
&lt;li&gt;Tools and Browser DevTools for DOM Exploration&lt;/li&gt;
&lt;li&gt;Best Practices for DOM Manipulation&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  1. Introduction
&lt;/h2&gt;

&lt;p&gt;When you open a website in your browser, you see buttons, text, images, and various interactive elements. But have you ever wondered how your browser understands and organizes all these parts of a webpage? The answer lies in something called the Document Object Model (DOM).&lt;/p&gt;

&lt;p&gt;The DOM serves as the foundation of frontend development. It’s a programming interface that allows developers to structure, access, and modify the content and appearance of a webpage dynamically. Without the DOM, modern interactive websites as we know them would not exist.&lt;/p&gt;

&lt;p&gt;For beginners starting in frontend development, understanding the DOM is one of the most crucial first steps. Once you grasp how the DOM works, you’ll be able to:&lt;/p&gt;

&lt;p&gt;Dynamically update content on a webpage.&lt;/p&gt;

&lt;p&gt;Handle user interactions like clicks, form submissions, and keyboard events.&lt;/p&gt;

&lt;p&gt;Build more interactive and responsive user experiences.&lt;/p&gt;

&lt;p&gt;In this article, we’ll break down the DOM in a beginner-friendly way, explore its structure, show you how to interact with it using JavaScript, and highlight best practices along the way.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. What is the DOM?
&lt;/h2&gt;

&lt;p&gt;The Document Object Model (DOM) is a structured representation of an HTML or XML document. Think of it as a live map of your webpage that your browser creates when it loads a page.&lt;/p&gt;

&lt;p&gt;When you write HTML code 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&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;title&amp;gt;&lt;/span&gt;My First Webpage&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;h1&amp;gt;&lt;/span&gt;Hello, World!&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;This is my first webpage.&lt;span class="nt"&gt;&amp;lt;/p&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;Your browser takes this code and builds a tree-like structure that represents every element, attribute, and piece of text. This structure is the DOM.&lt;/p&gt;

&lt;p&gt;At its core, the DOM:&lt;/p&gt;

&lt;p&gt;Represents the document as a tree of objects.&lt;/p&gt;

&lt;p&gt;Allows programming languages (like JavaScript) to interact with and manipulate the document’s content, structure, and style.&lt;/p&gt;

&lt;p&gt;Updates automatically when changes are made, allowing for dynamic content.&lt;/p&gt;

&lt;p&gt;In simple terms: HTML is the source, the DOM is the live version your browser uses.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Characteristics of the DOM:
&lt;/h3&gt;

&lt;p&gt;Object-Oriented: Everything in the DOM is represented as an object (elements, attributes, text).&lt;/p&gt;

&lt;p&gt;Hierarchical: Elements are nested inside one another, forming a tree.&lt;/p&gt;

&lt;p&gt;Dynamic: The DOM can be changed in real-time using JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Why is the DOM Important in Frontend Development?
&lt;/h2&gt;

&lt;p&gt;The DOM is at the heart of almost everything you do as a frontend developer. It bridges the gap between your code and what the user sees and interacts with on the screen. Let’s explore why it's so important:&lt;/p&gt;

&lt;h3&gt;
  
  
  3.1. Dynamic User Interfaces
&lt;/h3&gt;

&lt;p&gt;Without the DOM, webpages would be static, once loaded, they would never change. But thanks to the DOM, developers can:&lt;/p&gt;

&lt;p&gt;Add or remove elements.&lt;/p&gt;

&lt;p&gt;Update content without reloading the page.&lt;/p&gt;

&lt;p&gt;Show or hide parts of the page based on user actions.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;greeting&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Welcome back!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code changes the text content of an element dynamically.&lt;/p&gt;

&lt;h3&gt;
  
  
  3.2. User Interaction Handling
&lt;/h3&gt;

&lt;p&gt;When users interact with a webpage (clicking buttons, submitting forms, hovering over elements), the DOM allows developers to capture these events and respond accordingly.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Show a message when a button is clicked.&lt;/li&gt;
&lt;li&gt;Validate a form before submission.&lt;/li&gt;
&lt;li&gt;Animate elements on user actions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3.3. Powering Modern Web Frameworks
&lt;/h3&gt;

&lt;p&gt;Modern frontend frameworks like React, Angular, and Vue work heavily with the DOM (or even virtual DOMs) to create smooth, efficient updates to the user interface.&lt;/p&gt;

&lt;p&gt;Understanding the DOM is essential even if you plan to work with these frameworks, because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;They build upon DOM principles.&lt;/li&gt;
&lt;li&gt;You’ll often need to work directly with the DOM for custom behaviors.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3.4. Debugging and Browser DevTools
&lt;/h3&gt;

&lt;p&gt;When debugging your frontend code, most of your work involves inspecting and manipulating the DOM via browser developer tools. A solid understanding of the DOM helps you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Diagnose layout problems.&lt;/li&gt;
&lt;li&gt;Understand how CSS applies to elements.&lt;/li&gt;
&lt;li&gt;Verify event bindings.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  4. Understanding the DOM Tree Structure
&lt;/h2&gt;

&lt;p&gt;The DOM is often visualized as a tree, where every part of your HTML document becomes a node in the tree. Understanding this tree structure makes it easier to navigate, select, and manipulate elements using JavaScript.&lt;/p&gt;

&lt;p&gt;Let’s break it down:&lt;/p&gt;

&lt;h3&gt;
  
  
  4.1. The Tree Analogy
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Root Node: The very top of the tree is the document object. Everything starts here.&lt;/li&gt;
&lt;li&gt;Element Nodes: Each HTML tag (like , , &lt;h1&gt;, &lt;/h1&gt;
&lt;p&gt;) becomes an element node.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;Text Nodes: The actual text inside elements becomes text nodes.&lt;/li&gt;
&lt;li&gt;Attribute Nodes: Attributes (like class, id, and src) are nodes attached to their respective elements.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4.2. A Simple Example
&lt;/h3&gt;

&lt;p&gt;Consider this HTML code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;DOM Example&amp;lt;/title&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;h1&amp;gt;Hello World&amp;lt;/h1&amp;gt;
    &amp;lt;p&amp;gt;This is a paragraph.&amp;lt;/p&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;The DOM tree would look something like this:&lt;br&gt;
Document&lt;br&gt;
└── html&lt;br&gt;
    ├── head&lt;br&gt;
    │   └── title&lt;br&gt;
    │       └── "DOM Example"&lt;br&gt;
    └── body&lt;br&gt;
        ├── h1&lt;br&gt;
        │   └── "Hello World"&lt;br&gt;
        └── p&lt;br&gt;
            └── "This is a paragraph."&lt;/p&gt;
&lt;h3&gt;
  
  
  4.3. Why is the Tree Important?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;You can move up and down the tree using JavaScript.&lt;/li&gt;
&lt;li&gt;You can select parent, child, or sibling elements.&lt;/li&gt;
&lt;li&gt;You can add or remove branches (nodes) dynamically.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  4.4. The Parent-Child Relationship
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; is a child of &lt;code&gt;&amp;lt;html&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; are children of &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The text "Hello World" is a child of &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  4.5. Visualizing the DOM
&lt;/h3&gt;

&lt;p&gt;Visualizing the DOM tree is extremely helpful for beginners because it helps you understand how elements are connected.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdhmhl9c8a97lb0lmhusr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdhmhl9c8a97lb0lmhusr.png" alt="Image description" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  5. Interacting with the DOM using JavaScript
&lt;/h2&gt;

&lt;p&gt;Now that you understand what the DOM is and how it’s structured, let’s dive into how you can interact with it using JavaScript. This is where the DOM truly becomes powerful, allowing you to make your webpage dynamic and interactive.&lt;/p&gt;
&lt;h3&gt;
  
  
  5.1 Accessing Elements
&lt;/h3&gt;

&lt;p&gt;To manipulate an element, you first need to select it. JavaScript provides several ways to do this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;getElementById()&lt;/code&gt;&lt;br&gt;
Selects an element by its ID.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;greeting&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt;&lt;span class="o"&gt;!&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;greeting&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;greeting&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: Hello!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;getElementsByClassName()&lt;/code&gt;&lt;br&gt;
Selects elements by class name (returns a collection).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;message&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;First&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;message&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Second&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;messages&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementsByClassName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;message&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: First message&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;querySelector()&lt;/code&gt;&lt;br&gt;
Selects the first element that matches a CSS selector.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;heading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;h1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;querySelectorAll()&lt;/code&gt;&lt;br&gt;
Selects all elements that match a CSS selector.&lt;br&gt;
&lt;code&gt;let paragraphs = document.querySelectorAll("p");&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  5.2 Modifying Elements
&lt;/h3&gt;

&lt;p&gt;Once you’ve selected an element, you can modify its content, style, and attributes.&lt;/p&gt;

&lt;p&gt;Change Text Content&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;greeting&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Welcome!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Change HTML Content&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;greeting&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;strong&amp;gt;Welcome!&amp;lt;/strong&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Change Style&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;greeting&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5.3 Adding and Removing Elements
&lt;/h3&gt;

&lt;p&gt;You can also create, append, or remove elements dynamically.&lt;/p&gt;

&lt;p&gt;Create and Append&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;newParagraph&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;p&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;newParagraph&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;This is a new paragraph.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newParagraph&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remove Element&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;greeting&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6. Events and the DOM
&lt;/h2&gt;

&lt;p&gt;While manipulating the DOM allows you to change the webpage structure and content, events are what make your webpage interactive. An event occurs when the user or the browser does something, like clicking a button, moving the mouse, submitting a form, or pressing a key.&lt;/p&gt;

&lt;p&gt;The DOM allows you to listen for these events and execute JavaScript code in response.&lt;/p&gt;

&lt;h3&gt;
  
  
  6.1 Common DOM Events
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Event&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;click&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;When an element is clicked&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;mouseover&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;When the mouse hovers over an element&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;mouseout&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;When the mouse leaves an element&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;keydown&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;When a keyboard key is pressed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;submit&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;When a form is submitted&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;load&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;When the page has finished loading&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  6.2 Adding Event Listeners
&lt;/h3&gt;

&lt;p&gt;The most common way to handle events is by using the addEventListener() method.&lt;/p&gt;

&lt;p&gt;Example: Button Click&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="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"myButton"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Click Me!&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"result"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;myButton&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;result&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Button was clicked!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the user clicks the button, the text inside the &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; tag updates dynamically.&lt;/p&gt;

&lt;h2&gt;
  
  
  6.3 Why Use Event Listeners?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Separation of Concerns: Keeps HTML and JavaScript code separate.&lt;/li&gt;
&lt;li&gt;Multiple Handlers: You can attach multiple listeners to the same element.&lt;/li&gt;
&lt;li&gt;Flexibility: Allows better control over complex user interactions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  6.4 Other Example: Form Submission
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;form&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"myForm"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"nameInput"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Submit&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"displayName"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;form&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;myForm&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;display&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;displayName&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;form&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;submit&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;preventDefault&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Prevents page reload&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;nameInput&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;display&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`Hello, &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;!`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpwgm5yv1hwogsrsxmhod.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpwgm5yv1hwogsrsxmhod.png" alt="Image description" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  7.Common Mistakes Beginners Make with the DOM
&lt;/h2&gt;

&lt;p&gt;As you start working with the DOM, it’s natural to run into a few pitfalls. Let’s go over some of the most common mistakes and how to avoid them.&lt;/p&gt;

&lt;h3&gt;
  
  
  7.1 Trying to Access DOM Elements Before the Page Loads
&lt;/h3&gt;

&lt;p&gt;Problem:&lt;br&gt;
If you try to select or modify DOM elements before they exist in the browser, your code may fail.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;heading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;heading&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;heading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;If&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt; &lt;span class="nx"&gt;runs&lt;/span&gt; &lt;span class="nx"&gt;before&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;DOM&lt;/span&gt; &lt;span class="nx"&gt;has&lt;/span&gt; &lt;span class="nx"&gt;fully&lt;/span&gt; &lt;span class="nx"&gt;loaded&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;heading&lt;/span&gt; &lt;span class="nx"&gt;will&lt;/span&gt; &lt;span class="nx"&gt;be&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;causing&lt;/span&gt; &lt;span class="nx"&gt;an&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Solution:&lt;br&gt;
Use the DOMContentLoaded event to ensure your code runs after the DOM is ready.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;DOMContentLoaded&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;heading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;heading&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;heading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  7.2 Overusing innerHTML
&lt;/h3&gt;

&lt;p&gt;While innerHTML is powerful, it’s easy to misuse it and accidentally introduce bugs or security vulnerabilities like Cross-Site Scripting (XSS).&lt;/p&gt;

&lt;p&gt;Better practice: Use textContent or DOM methods to modify elements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Safe Text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  7.3 Forgetting to Remove Event Listeners
&lt;/h3&gt;

&lt;p&gt;When dynamically adding and removing elements, forgetting to remove event listeners can cause memory leaks and unexpected behavior.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  7.4 Mixing Inline JavaScript with DOM Manipulation
&lt;/h3&gt;

&lt;p&gt;While it’s possible to use inline onclick attributes:&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="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;onclick=&lt;/span&gt;&lt;span class="s"&gt;"alert('Hello!')"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Click Me&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Best practice:&lt;br&gt;
Separate your JavaScript code from HTML by using addEventListener(). This makes your code more maintainable and scalable.&lt;/p&gt;
&lt;h3&gt;
  
  
  7.5 Not Using Efficient Selectors
&lt;/h3&gt;

&lt;p&gt;Using getElementById() is faster and more specific.&lt;/p&gt;

&lt;p&gt;Avoid using overly broad selectors that may select multiple unintended elements.&lt;/p&gt;
&lt;h2&gt;
  
  
  8. Tools and Browser DevTools for DOM Exploration
&lt;/h2&gt;

&lt;p&gt;One of the best ways to learn and work with the DOM is by using the powerful tools built into modern web browsers. These tools allow you to inspect, edit, and experiment with the DOM in real-time.&lt;/p&gt;
&lt;h3&gt;
  
  
  8.1 The Browser Developer Tools (DevTools)
&lt;/h3&gt;

&lt;p&gt;Almost every modern browser (Chrome, Firefox, Edge, Safari) includes DevTools. You can usually open them by:&lt;/p&gt;

&lt;p&gt;Right-click on any element on the page and select Inspect.&lt;/p&gt;

&lt;p&gt;Or press F12 or Ctrl+Shift+I (Windows/Linux) or Cmd+Option+I (Mac).&lt;/p&gt;
&lt;h3&gt;
  
  
  8.1.1 Elements Panel
&lt;/h3&gt;

&lt;p&gt;Displays the live DOM tree of the current webpage.&lt;/p&gt;

&lt;p&gt;You can expand and collapse elements to see the structure.&lt;/p&gt;

&lt;p&gt;You can edit HTML directly to see instant changes.&lt;/p&gt;
&lt;h3&gt;
  
  
  8.1.2 Console Panel
&lt;/h3&gt;

&lt;p&gt;Allows you to run JavaScript directly in the context of the webpage.&lt;/p&gt;

&lt;p&gt;Great for testing DOM manipulations quickly.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;h1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Changed via Console!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  8.1.3 Other Useful Panels
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Network: See how resources load.&lt;/li&gt;
&lt;li&gt;Sources: Debug JavaScript.&lt;/li&gt;
&lt;li&gt;Performance: Analyze page speed.&lt;/li&gt;
&lt;li&gt;Accessibility: Review accessibility issues.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  8.2 Online Playground Tools
&lt;/h3&gt;

&lt;p&gt;Many online tools allow you to experiment with the DOM:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CodePen (&lt;a href="https://codepen.io" rel="noopener noreferrer"&gt;https://codepen.io&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;JSFiddle (&lt;a href="https://jsfiddle.net" rel="noopener noreferrer"&gt;https://jsfiddle.net&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;JSBin (&lt;a href="https://jsbin.com" rel="noopener noreferrer"&gt;https://jsbin.com&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are great for practicing DOM manipulation without having to set up files on your computer.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. Best Practices for DOM Manipulation
&lt;/h2&gt;

&lt;p&gt;As you grow more comfortable working with the DOM, following best practices will help you write more efficient, maintainable, and secure code. Let’s cover some important tips:&lt;/p&gt;

&lt;h3&gt;
  
  
  9.1 Access Elements Efficiently
&lt;/h3&gt;

&lt;p&gt;Use &lt;code&gt;getElementById()&lt;/code&gt; when possible — it’s the fastest.&lt;/p&gt;

&lt;p&gt;Minimize repeated DOM queries — store elements in variables if used multiple times.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;submitBtn&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// reuse `button` instead of querying again&lt;/span&gt;
&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;handleSubmit&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  9.2 Avoid Unnecessary Reflows and Repaints
&lt;/h3&gt;

&lt;p&gt;Manipulating the DOM excessively or inefficiently can slow down your page. If you're making multiple changes, try:&lt;/p&gt;

&lt;p&gt;Modifying elements outside of the visible document (using DocumentFragment).&lt;/p&gt;

&lt;p&gt;Minimizing layout calculations in loops.&lt;/p&gt;

&lt;h3&gt;
  
  
  9.3 Sanitize User Input
&lt;/h3&gt;

&lt;p&gt;Never directly insert user input into the DOM using innerHTML. This can lead to security issues like Cross-Site Scripting (XSS).&lt;/p&gt;

&lt;p&gt;Instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;userInput&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  9.4 Use Event Delegation
&lt;/h3&gt;

&lt;p&gt;Instead of attaching multiple event listeners to many child elements, attach one listener to a parent element.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;list&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tagName&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;LI&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This approach is more efficient, especially for dynamic content.&lt;/p&gt;

&lt;h3&gt;
  
  
  9.5 Separate Concerns
&lt;/h3&gt;

&lt;p&gt;Keep your HTML, CSS, and JavaScript separate.&lt;/p&gt;

&lt;p&gt;Avoid mixing inline JavaScript (onclick="...") with your HTML.&lt;/p&gt;

&lt;p&gt;This leads to cleaner, more maintainable code.&lt;/p&gt;

&lt;h3&gt;
  
  
  9.6 Use DOMContentLoaded
&lt;/h3&gt;

&lt;p&gt;Make sure the DOM is fully loaded before manipulating it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;DOMContentLoaded&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Safe DOM manipulation here&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  9.7 Clean Up Event Listeners
&lt;/h3&gt;

&lt;p&gt;When removing elements dynamically, ensure you also remove any event listeners to prevent memory leaks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  10. Conclusion
&lt;/h2&gt;

&lt;p&gt;The Document Object Model (DOM) is truly the foundation of frontend development. Every time you build a webpage, you're essentially creating a DOM structure that your browser understands and renders.&lt;/p&gt;

&lt;p&gt;For beginners, mastering the DOM unlocks the ability to:&lt;/p&gt;

&lt;p&gt;✅ Create dynamic, interactive webpages&lt;br&gt;
✅ Respond to user actions with JavaScript&lt;br&gt;
✅ Modify page content on the fly&lt;br&gt;
✅ Build confidence for learning modern frontend frameworks like React, Vue, or Angular&lt;/p&gt;

&lt;p&gt;Key Takeaways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The DOM represents your HTML as a live tree structure.&lt;/li&gt;
&lt;li&gt;JavaScript allows you to interact with and manipulate the DOM.&lt;/li&gt;
&lt;li&gt;Events are key to making webpages interactive.&lt;/li&gt;
&lt;li&gt;Browser DevTools are your best friend for exploring and debugging the DOM.&lt;/li&gt;
&lt;li&gt;Always follow best practices for efficient, safe, and maintainable code.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Next Steps for You as a Beginner:&lt;/p&gt;

&lt;p&gt;Practice manipulating the DOM using simple projects (to-do list, calculator, form validation).&lt;/p&gt;

&lt;p&gt;Experiment using DevTools on existing websites.&lt;/p&gt;

&lt;p&gt;Gradually move on to understanding Virtual DOM (used by modern frameworks).&lt;/p&gt;

&lt;p&gt;💡 Always remember:&lt;/p&gt;

&lt;p&gt;If you master the DOM, you're already halfway to becoming a great frontend developer!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>frontend</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
