Back to Cheat Sheets

Writing

JavaScript for Beginners Series - Part 10 (English & Darija)

Part 10 of the JavaScript for Beginners series by Ibtissam Oulahchoum. This guide introduces the DOM (Document Object Model)—the bridge between JavaScript and HTML. Learn how to Select and Manipulate web elements to create interactive pages. Includes simplified explanations in Moroccan Darija.

JavaScript DOM Web Development Frontend Darija Interactivity

January 24, 2026 · 3 min read

JavaScript for Beginners Series - Part 10 (English & Darija)

JavaScript for Beginners: Part 10

The DOM: Bringing Your Website to Life

Welcome to Part 10! Today we explore the DOM (Document Object Model). This is arguably the most critical concept in web development because it is what makes websites interactive.

1️⃣ What is the DOM?

The DOM is the interface (the bridge) that allows JavaScript to interact with your web page.

  • Without the DOM: JavaScript is just a calculator.
  • With the DOM: JavaScript becomes a powerful tool that can change everything you see on the screen.
🇲🇦 Darija:
الـ DOM هو "الوسيط" اللي كيخلي جافاسكريبت تهضر مع HTML. بلا بيه، الصفحة كتبقى جامدة (Static) ومافيهاش الروح. هو اللي كيعطينا القدرة نبدلو أي حاجة ف الصفحة غير بالكود.

2️⃣ How it Works: Select & Manipulate

The browser turns your HTML into a "tree" structure. JavaScript can access this tree to perform two main actions:

Select (التحديد)

Before you change something, you have to find it. We use methods like document.querySelector() to "pick" elements from the page.

🇲🇦 Darija:
باش تحكم فشي حاجة، خاصك بعدا "تشير" ليها. document.querySelector هي أحسن طريقة باش تختار أي Element بغيتي (سواء بالـ Class ولا ID) بحال كيفما كدير فـ CSS.

Manipulate (التحكم)

Once selected, you can change the content (textContent), the look (style), or the behavior (classList) of that element dynamically.

🇲🇦 Darija:
من بعد ما شديتي الـ Element وحطيتيه فـ Variable، تقدر دير بيه لي بغيتي: تبدل الكلون (style.color)، تبدل الكثبة اللي وسطو (textContent)، أو حتى تزيد ليه Class جديد باش تبدلو كامل.

💻 Code Example

See how we grab an element and transform it instantly:

// Imagine this HTML: <h1 class="title">Old Text</h1>

// 1. SELECTION (Finding the element)
// querySelector finds the FIRST element that matches the CSS selector
const titleElement = document.querySelector('.title');

// 2. MANIPULATION (Changing the element)
function updatePage() {
    // Change the text inside the tag
    titleElement.textContent = "Hello from JavaScript!";

    // Change CSS styles directly (Inline Styles)
    titleElement.style.color = "blue";
    titleElement.style.fontSize = "3rem";

    // Add a CSS class (The cleaner, modern way to style)
    titleElement.classList.add('active');
}

// Run the function to see the changes happen
updatePage();

📝 Key Takeaways (الملخص)

  • The Document Object Model (DOM): This acts as the essential connection between your JavaScript code and your HTML structure, turning static pages into interactive experiences.
    • Darija: هو الخيط اللي كيربط الجافاسكريبت بالـ HTML باش الصفحة تولي حية وتفاعلية.
  • Selecting with querySelector: You can use this method to target any element on your page using standard CSS selectors (like .class or #id).
    • Darija: كنشدو بيه أي عنصر بغينا نخدمو عليه فالصفحة باستعمال نفس السميات اللي كنخدمو بيهم ف الـ CSS.
  • The textContent Property: This allows you to dynamically update the text inside an element without needing to refresh the browser.
    • Darija: هي الخاصية اللي كتمكنا نبدلو الكلام اللي مكتوب وسط أي بلاصة فالموقع غير بالكود.
  • The style Object: This gives you the power to change CSS properties (like colors and fonts) directly through JavaScript in real-time.
    • Darija: كتعطيك التحكم الكامل باش تبدل الألوان، العبارات، وأي حاجة عندها علاقة بالديكور ديال الصفحة فالحين.
  • The classList Tool: Use this to add or remove CSS classes, which is the cleanest way to manage complex style changes on your website.
    • Darija: هي الطريقة النقية باش تزيد أو تحيد "Classes" على العناصر، وهكا كتحكم ف الـ Design بطريقة احترافية.

Next up: Part 11 – Event Listeners: Making buttons actually work

Related Cheat Sheets

Mentorship

Want to learn, not just read?

These cheat sheets are the short version. If you want the long one, I teach — one on one, at your pace, on what you are actually trying to build.

Let's talk
  • Learn with guidance

    I will walk you through the fundamentals, review your code, and help you grow past the tutorials.

  • Choose your career path

    Not sure which direction to take? We will talk it through and map a path that fits your strengths and your goals.

Want to work together?

I'm always open to discussing new projects.

Get in Touch