Guest Mode:

BCA Student Stories & UpdatesLive

You
Your StorySign in & share
Er. Manoj Kumar
D5
Er. ManojActive nowPages
Day 28DOM & Web APIs2 Hours Practical
Push to GitHub to Complete

DOM Selection: querySelector, textContent, innerHTML & Dynamic Styles

The Document Object Model (DOM) is an object-oriented tree representation of the webpage. Through the DOM API, JavaScript can inspect, add, remove, and alter HTML tags, attributes, and CSS styling in real-time without reloading the page.

Interactive Learning Roadmap

Day 28 Step-by-Step Practical Flow

🎯1. What You Will Learn Today

✔Understand the Document Object Model (DOM) tree architecture.
✔Target elements with document.querySelector() and document.querySelectorAll().
✔Modify element text safely with textContent vs innerHTML.
✔Update inline CSS styles dynamically with element.style and classList.toggle().
Day 28 MasterclassDOM & Web APIs

DOM Selection: querySelector, textContent, innerHTML & Dynamic Styles — Comprehensive Practical Guide

Har concept ko visual mental models, code anatomy aur practical industry tips ke sath samjhein.

Real-World Purpose Aur Zaroorat

The Document Object Model (DOM) is an object-oriented tree representation of the webpage. Through the DOM API, JavaScript can inspect, add, remove, and alter HTML tags, attributes, and CSS styling in real-time without reloading the page.

document.querySelector(selector): Returns the FIRST element matching the CSS selector (class, ID, tag).
document.querySelectorAll(selector): Returns a NodeList of ALL matching elements.
textContent: Sets or retrieves plain text safely (immune to XSS script injection).
innerHTML: Parses and renders HTML markup (use cautiously with untrusted input).
element.style.property: Sets inline CSS styles (e.g. element.style.backgroundColor = "blue").
element.classList.add(), remove(), toggle(): Cleanest way to alter appearance by toggling pre-defined CSS classes.
Dimaag Mein Bithane Ka Model

"HTML is the static blueprint drawing of a house; the DOM is the physical constructed building with electrical wiring; JavaScript is the resident who can flip light switches, paint walls, and rearrange furniture inside."

💡 Pro Tip: Code ko ratta mat maaro; imagine karo ki browser har tag ko visually kaise draw karta hai.

👨‍🏫3. Teacher Demonstration Code

See how querySelector targets HTML elements and updates text and background color on the fly.

Selecting Elements and Updating Card Status Dynamicallyhtml
<!DOCTYPE html>
<html>
<head>
  <style>
    .status-card {
      padding: 16px;
      border-radius: 8px;
      background: #f1f5f9;
      font-family: sans-serif;
    }
    .active-badge {
      color: #16a34a;
      font-weight: bold;
    }
  </style>
</head>
<body>
  <div class="status-card">
    <h3 id="student-header">Student Record</h3>
    <p>Status: <span id="status-pill">Pending</span></p>
  </div>

  <script>
    // 1. Select elements
    const header = document.querySelector("#student-header");
    const pill = document.querySelector("#status-pill");

    // 2. Update content and styles
    header.textContent = "Aarav Sharma (BCA 1st Sem)";
    pill.textContent = "Verified & Active";
    pill.classList.add("active-badge");
  </script>
</body>
</html>

2. Hands-On Practical Lab: Follow Instructions in VS Code

Code like a professional software engineer! Follow the step-by-step instructions below in Visual Studio Code (VS Code) on your PC, test your output locally, and push to GitHub.

2 Coding Tasks
Interactive Coding TestAuto-Evaluates as you type

Day 28 Practical Task Test Studio

Test Score:0 / 2 Passed
1. Practical Task Specifications & Live Test Checklist:Type code below to pass tests
Task 1Update portal-title textContent

Select #portal-title with querySelector and update textContent to "Nextsem BCA Hub".

⏳ WAITING
Task 2Update badge text and style color

Select #badge, update textContent to "Active", and set style.color to "#16a34a".

⏳ WAITING
2. Type HTML & CSS Code:index.html
index.html
⚡ Real-Time Testing Active
Tab inserts 2 spaces • Live DOM refresh355 chars
Live Browser Output:
🔒 http://localhost:5500/index.html
Live
Renders live HTML & CSS typed on the left.
Interactive Bug Detective

Spot the Bug: Script Executing Before DOM Element Exists

Tap or click on the exact line below that contains the error:

Click any code line
⚠️ Broken Code Inspector
Tap buggy line
1
<head>
2
<script>
3
// Script runs before <body> is parsed!
4
const heading = document.querySelector("#my-heading");
5
heading.textContent = "New Title"; // Throws TypeError: Cannot set properties of null
6
</script>
7
</head>
8
<body>
9
<h1 id="my-heading">Original Title</h1>
10
</body>
Stuck? Need a detective clue before checking the solution?

Senior Developer Forensic Analysis:

The browser executes <script> in <head> immediately before the <body> HTML is parsed, so document.querySelector("#my-heading") returns null.

Golden Rule: Always validate code syntax and security attributes before pushing to GitHub!

📝Independent Practice: Assignment

📄 announcement-banner.html

Interactive University Campus Announcement Banner

  • •Create day-28/index.html with an announcement card component.
  • •Use document.querySelector() to target card title, date, and priority tag.
  • •Write JavaScript that updates the text and applies dynamic styling based on priority.
  • •Verify in the browser that all DOM updates apply cleanly on initial page load.
Submission Evaluation Criteria: Ensure DOM elements are targeted with querySelector and manipulated using textContent.
Exact Assignment Solution Code: announcement-banner.html

Open Visual Studio Code on your PC (code .), create announcement-banner.html, paste this complete step-by-step verified code, test in your browser, and push to your GitHub repo:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>BCA Day 28 - DOM Selection & Dynamic Styling</title>
  <style>
    * { box-sizing: border-box; margin: 0; padding: 0; }
    body {
      font-family: 'Segoe UI', Tahoma, sans-serif;
      background: #0b1120;
      color: white;
      min-height: 100vh;
      display: flex;
      justify-content: center;
      align-items: center;
      padding: 20px;
    }
    .wrapper { max-width: 500px; width: 100%; }
    .announcement-card {
      background: #1e293b;
      border: 1px solid #334155;
      border-radius: 16px;
      padding: 24px;
      transition: all 0.3s ease;
    }
    .priority-badge {
      display: inline-block;
      padding: 4px 10px;
      border-radius: 50px;
      font-size: 11px;
      font-weight: bold;
      text-transform: uppercase;
      margin-bottom: 12px;
    }
    .card-title { font-size: 18px; margin-bottom: 8px; }
    .card-date { font-size: 12px; color: #94a3b8; margin-bottom: 12px; }
    .card-body { font-size: 13px; color: #cbd5e1; line-height: 1.5; }

    /* Dynamic Priority Themes applied via DOM */
    .priority-high {
      border-left: 5px solid #ef4444;
      background: #1c1917;
    }
    .priority-high .priority-badge { background: #ef4444; color: white; }
  </style>
</head>
<body>
  <div class="wrapper">
    <div class="announcement-card" id="campusCard">
      <span class="priority-badge" id="priorityTag">Normal</span>
      <h2 class="card-title" id="cardTitle">Loading Announcement...</h2>
      <div class="card-date" id="cardDate">--</div>
      <p class="card-body" id="cardBody">Fetching campus records...</p>
    </div>
  </div>

  <script>
    // 1. Select DOM elements using document.querySelector
    const card = document.querySelector("#campusCard");
    const priorityTag = document.querySelector("#priorityTag");
    const cardTitle = document.querySelector("#cardTitle");
    const cardDate = document.querySelector("#cardDate");
    const cardBody = document.querySelector("#cardBody");

    // 2. Data payload
    const notice = {
      title: "BCA 1st Semester Term-End Practical Exam Schedule",
      date: "October 2026 Notification",
      body: "All registered BCA students must push their verified GitHub repositories for Days 1–30 prior to the final laboratory viva examination.",
      priority: "high"
    };

    // 3. Update DOM content dynamically
    cardTitle.textContent = notice.title;
    cardDate.textContent = notice.date;
    cardBody.textContent = notice.body;
    priorityTag.textContent = notice.priority.toUpperCase() + " PRIORITY";

    // 4. Apply dynamic style classes
    if (notice.priority === "high") {
      card.classList.add("priority-high");
    }
  </script>
</body>
</html>
Verified Assignment Code Solution (100% Tested & Ready to Run)

🎓4. Viva Check: Mandatory Conceptual Test

Why is textContent preferred over innerHTML when inserting user-generated text into a webpage?

5. Mandatory Step: Push to GitHub to Unlock Next Lesson

Target Repo: html-css-projects

Windows 11 Terminal / VS Code
1$
mkdir day-28
Create a new project folder (day-28)
2$
cd day-28
Change working directory to day-28
3$
git checkout -b feature/day-28-dom-selection
4$
git add index.html
5$
git commit -m "feat(day-28): implement dom selection textcontent and style manipulation"
Commit staged changes with a descriptive message
6$
git push origin feature/day-28-dom-selection
Push local commits directly to your remote GitHub repository
⌨️ Paste into terminal:Ctrl + V✨ Word wrap active (no horizontal cutoff)
Completion Prerequisites VerificationIncomplete Steps
Google Login
✔ Required
VS Code Implementation
Step 4 Viva Check
Own GitHub Project
Required

Exact GitHub Setup Guide & Expected Structure

Day 28 Requirements

Follow these exact folder and file names to prevent verification errors.

1. GitHub Repository
html-css-projects
Must be set to Public
2. Exact FolderNEW
day-28/ or bca-day-28/
Create inside repo root
3. Exact File NameREQUIRED
index.html
⚠️ No spaces or custom names
4. What to Submit Below
https://github.com/YOU/html-css-projects
Or direct link to index.html
Terminal Commands to Create & Push Day 28
1$
# 1. Enter your repository directory
2$
cd html-css-projects
Change working directory to html-css-projects
3$
# 2. Create the exact folder for Day 28
4$
mkdir day-28
Create a new project folder (day-28)
5$
cd day-28
Change working directory to day-28
6$
# 3. Create your code file: index.html
7$
# (Write your Day 28 homework code inside index.html)
8$
# 4. Save, stage, commit and push to GitHub:
9$
git add .
Stage all modified files and new assets for commit
10$
git commit -m "Day 28: DOM Selection: querySelector, textContent, innerHTML & Dynamic Styles"
Commit staged changes with a descriptive message
11$
git push origin main
Push local commits directly to your remote GitHub repository
⌨️ Paste into terminal:Ctrl + V✨ Word wrap active (no horizontal cutoff)
How to Avoid "Could not find your practical code file" Errors:
1.Use Lowercase index.html: Avoid spaces or custom names like Alan Turing..html or Index.HTML. Linux/GitHub servers are strictly case-sensitive.
2.Separate Day Folders: Create a new folder day-28/ for today so you don't overwrite previous days.
3.Ensure Public Visibility: If your GitHub repo is Private, automated validation cannot inspect your code. Set it to Public.
4.Check on GitHub Website: Before clicking "Verify", open your repo in Google Chrome to confirm your files were pushed to branch main.
📁 github.com/YOUR_USERNAME/html-css-projects
Branch: main
README.md# BCA Practical Portfolio overview
day-01/Day 1 Prior Lesson
└──index.html
day-02/Day 2 Prior Lesson
└──index.html
day-03/Day 3 Prior Lesson
└──index.html
day-04/Day 4 Prior Lesson
└──index.html
day-05/Day 5 Prior Lesson
└──index.html
day-06/Day 6 Prior Lesson
└──index.html
day-07/Day 7 Prior Lesson
└──index.html
day-08/Day 8 Prior Lesson
└──index.html
day-09/Day 9 Prior Lesson
└──index.html
day-10/Day 10 Prior Lesson
└──index.html
└──styles.css
day-11/Day 11 Prior Lesson
└──index.html
day-12/Day 12 Prior Lesson
└──index.html
day-13/Day 13 Prior Lesson
└──index.html
day-14/Day 14 Prior Lesson
└──index.html
day-15/Day 15 Prior Lesson
└──index.html
day-16/Day 16 Prior Lesson
└──index.html
day-17/Day 17 Prior Lesson
└──index.html
day-18/Day 18 Prior Lesson
└──index.html
day-19/Day 19 Prior Lesson
└──index.html
day-20/Day 20 Prior Lesson
└──index.html
└──styles.css
day-21/Day 21 Prior Lesson
└──index.html
day-22/Day 22 Prior Lesson
└──index.html
day-23/Day 23 Prior Lesson
└──index.html
day-24/Day 24 Prior Lesson
└──index.html
day-25/Day 25 Prior Lesson
└──index.html
day-26/Day 26 Prior Lesson
└──index.html
day-27/Day 27 Prior Lesson
└──index.html
day-28/✨ CREATE THIS FOLDER FOR TODAY (Day 28)
└──index.htmlMust contain: document.querySelector(), .textContent, .style, .classList.toggle()
Sequential Progression Enforced

You are welcome to read all notes, inspect code snippets, and practice all exercises of Day 28 freely! To officially submit your GitHub repository and unlock subsequent days in your portfolio, please complete Day 27: JavaScript Objects, Nested Data & JSON Serialization Basics first.

Complete Day 27 First
Day 27: JavaScript Objects, Nested Data & JSON Serialization Basics
WhatsApp
Curriculum & Practical Systems Authored by Er. Manoj Kumar
NextSem Academy • BCA Practical Learning Portal