Internet Programming Laboratory

Unit 6: JavaScript DOM & BOM

DOM Tree, Selection, Manipulation, classList, Event Bubbling & Capturing, DOM Traversal, BOM (window, history, location, navigator), setTimeout, setInterval, IntersectionObserver, MutationObserver — bridging JavaScript to the visible page.

🏢 Industry-Aligned  |  📝 15 MCQs (Bloom's Taxonomy)  |  🔬 5 Lab Exercises  |  💼 Interview Prep

Section 1

Why This Chapter Matters in 2025

You already know JavaScript syntax — variables, functions, loops, promises. But here's the honest truth: JavaScript without DOM access is a brain without a body. It can think, but it can't do anything the user can see. The DOM (Document Object Model) is the bridge between your JavaScript code and the actual pixels on screen.

Every single time you've seen a website update without a full page reload — a notification badge appearing on Flipkart, a cart total recalculating on Swiggy, a stock price flashing green on Zerodha — that's JavaScript talking to the DOM. And the BOM (Browser Object Model) is what gives you access to the browser itself: the URL bar, navigation history, screen dimensions, and timers.

🏢 Industry Connection — DOM Powers Every Indian Super-App

Flipkart — When you add an item to cart, JavaScript calls createElement() to build a new cart-item card, appendChild() to inject it into the sidebar, and classList.add('slide-in') to animate it. Zero page reloads.

Swiggy — Infinite scroll? That's IntersectionObserver watching a sentinel element. When it enters the viewport, fetch() loads the next batch of restaurants and insertAdjacentHTML() injects the cards.

Zerodha (Kite) — Stock prices update 5 times per second via WebSocket. Each update uses querySelector() to find the price cell, textContent to write the new value, and classList.toggle() to flash green or red.

CRED — Those buttery smooth card flip animations? classList.add('flipped') triggers CSS transitions. The classList API is the secret weapon behind every modern animation library.

🇮🇳 Flipkart🇮🇳 Swiggy🇮🇳 Zerodha🇮🇳 CRED🇮🇳 PhonePe🇮🇳 Razorpay

Prerequisite Checklist ✅

  • ✅ Completed Unit 4 (JavaScript Core — variables, functions, objects, async/await)
  • ✅ Completed Unit 5 (or at least know basic HTML structure — you need a page to manipulate)
  • ✅ Chrome DevTools — you'll live in the Elements and Console tabs (F12)
  • ✅ Understand that HTML is a tree of nested elements — the DOM formalises this
The DOM specification was created by the W3C in 1998 to provide a language-neutral interface to HTML and XML documents. Before the DOM, Netscape and Internet Explorer had their own incompatible object models — leading to the infamous "This site is best viewed in..." banners. The DOM standardised everything. Today, every browser implements the same DOM API, which is why your JavaScript works identically on Chrome, Firefox, Safari, and Edge.
Section 2

Learning Outcomes — Bloom's Taxonomy

Bloom's LevelLearning Outcome
L1 — RememberRecall DOM selection methods (getElementById, querySelector, querySelectorAll) and BOM objects (window, history, location, navigator)
L2 — UnderstandExplain the difference between event bubbling and capturing, between innerHTML and textContent, and between NodeList and HTMLCollection
L3 — ApplyUse DOM manipulation methods (createElement, appendChild, removeChild, insertAdjacentHTML) to dynamically build UI components without page reload
L4 — AnalyzeDebug event propagation issues using DevTools, trace DOM traversal paths, and diagnose performance problems caused by excessive DOM mutations
L5 — EvaluateCompare IntersectionObserver vs scroll-event-based approaches for lazy loading and justify the performance benefits of the Observer pattern
L6 — CreateBuild a complete interactive product listing page with dynamic card generation, infinite scroll, classList-driven animations, and SPA-style navigation using the History API