BCA Student Stories & UpdatesLive
HTML5 Drag & Drop API (Building an Interactive Kanban Task Board)
The HTML5 Drag and Drop (DnD) API allows users to grab DOM elements with their mouse or pointer, drag them across the viewport, and drop them into designated target dropzones. This API powers modern project management tools like Trello, Jira, and GitHub Project Boards.
Day 45 Step-by-Step Practical Flow
🎯1. What You Will Learn Today
HTML5 Drag & Drop API (Building an Interactive Kanban Task Board) — Comprehensive Practical Guide
Har concept ko visual mental models, code anatomy aur practical industry tips ke sath samjhein.
The HTML5 Drag and Drop (DnD) API allows users to grab DOM elements with their mouse or pointer, drag them across the viewport, and drop them into designated target dropzones. This API powers modern project management tools like Trello, Jira, and GitHub Project Boards.
"Imagine a physical whiteboard with sticky notes categorized into columns (Planning, In Progress, Finished). Drag and drop lets you peel a sticky note off the whiteboard, carry it across to a new column, and press it firmly against the new column."
👨🏫3. Teacher Demonstration Code
See how cards are transferred between columns with animated drop indicators and clean DOM appending.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Drag and Drop Kanban</title>
<style>
body { font-family: system-ui, sans-serif; background: #060c18; color: #fff; padding: 24px; }
.board { display: flex; gap: 20px; max-width: 720px; margin: auto; }
.column { flex: 1; background: #0c1328; border: 2px dashed #1e293b; border-radius: 12px; padding: 16px; min-height: 250px; }
.column.drag-over { border-color: #38bdf8; background: #0f1d3a; }
.card { background: #1e293b; border: 1px solid #334155; padding: 12px; border-radius: 8px; margin-bottom: 10px; cursor: grab; }
</style>
</head>
<body>
<div class="board">
<div class="column" id="col-todo">
<h4>📋 To Do</h4>
<div class="card" draggable="true" id="c1">Study BCS-111 Networking</div>
</div>
<div class="column" id="col-done">
<h4>✅ Completed</h4>
<div class="card" draggable="true" id="c2">Setup VS Code Environment</div>
</div>
</div>
<script>
let dragged = null;
document.querySelectorAll(".card").forEach(c => {
c.addEventListener("dragstart", (e) => { dragged = e.target; });
});
document.querySelectorAll(".column").forEach(col => {
col.addEventListener("dragover", (e) => { e.preventDefault(); col.classList.add("drag-over"); });
col.addEventListener("dragleave", () => { col.classList.remove("drag-over"); });
col.addEventListener("drop", (e) => {
e.preventDefault();
col.classList.remove("drag-over");
if (dragged) col.appendChild(dragged);
});
});
</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.
Day 45 Practical Task Test Studio
Add draggable="true" attribute to task cards so the browser allows native dragging.
Call e.preventDefault() inside the dragover event listener to designate container as drop zone.
Inside the drop event handler, prevent default and append the dragged element into the drop column.
Spot the Bug: Drop Event Never Fires
Tap or click on the exact line below that contains the error:
Click any code lineconst column = document.getElementById("doneCol");// ❌ Missing dragover listener!column.addEventListener("drop", (e) => { console.log("Card dropped!"); column.appendChild(draggedItem);});Senior Developer Forensic Analysis:
By default, browser elements reject drops. Without an active dragover event listener that explicitly executes e.preventDefault(), the browser cancels the drop action and the "drop" event is never triggered.
📝Independent Practice: Assignment
📄 index.htmlBCA 3-Column Sprint Project Kanban Board
- •Build a 3-column Kanban workspace: "Backlog", "In Development", and "Verified & Completed".
- •Provide an "Add New Task" modal or input form to dynamically spawn new draggable cards.
- •Highlight columns dynamically with cyan borders when a card is dragged over them.
- •Persist all card positions in localStorage so refreshing the page restores the exact column state.
Open Visual Studio Code on your PC (code .), create index.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">
<title>BCA Day 45 - Kanban Board</title>
<style>
body { font-family: "Segoe UI", sans-serif; background: #060c18; color: #fff; padding: 24px; }
.header { max-width: 900px; margin: auto; display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; max-width: 900px; margin: auto; }
.col { background: #0c1328; border: 2px dashed #1e293b; border-radius: 12px; padding: 16px; min-height: 380px; }
.col.hovered { border-color: #38bdf8; background: #0f1e3d; }
.card { background: #1e293b; border: 1px solid #334155; padding: 12px; border-radius: 8px; margin-bottom: 10px; cursor: grab; user-select: none; }
</style>
</head>
<body>
<div class="header">
<h2>📋 BCA Sprint Kanban Board</h2>
<div>
<input type="text" id="taskInput" placeholder="New task..." />
<button id="addBtn">+ Add Card</button>
</div>
</div>
<div class="board">
<div class="col" id="col-backlog"><h4>📌 Backlog</h4><div class="card" draggable="true">Write Unit Tests</div></div>
<div class="col" id="col-progress"><h4>⚙️ In Progress</h4><div class="card" draggable="true">Canvas Pad</div></div>
<div class="col" id="col-done"><h4>✅ Completed</h4><div class="card" draggable="true">ES6 Setup</div></div>
</div>
<script>
let dragged = null;
function attach(card) {
card.addEventListener("dragstart", (e) => { dragged = e.target; });
}
document.querySelectorAll(".card").forEach(attach);
document.querySelectorAll(".col").forEach(col => {
col.addEventListener("dragover", (e) => { e.preventDefault(); col.classList.add("hovered"); });
col.addEventListener("dragleave", () => { col.classList.remove("hovered"); });
col.addEventListener("drop", (e) => {
e.preventDefault();
col.classList.remove("hovered");
if (dragged) col.appendChild(dragged);
});
});
</script>
</body>
</html>🎓4. Viva Check: Mandatory Conceptual Test
Which method on navigator.geolocation triggers continuous tracking of user coordinates as they move?
5. Mandatory Step: Push to GitHub to Unlock Next Lesson
Target Repo: html-css-projects
Exact GitHub Setup Guide & Expected Structure
Day 45 RequirementsFollow these exact folder and file names to prevent verification errors.
index.html: Avoid spaces or custom names like Alan Turing..html or Index.HTML. Linux/GitHub servers are strictly case-sensitive.day-45/ for today so you don't overwrite previous days.main.You are welcome to read all notes, inspect code snippets, and practice all exercises of Day 45 freely! To officially submit your GitHub repository and unlock subsequent days in your portfolio, please complete Day 44: Custom HTML5 Audio & Video Player (Media API & Real-time Progress Bar) first.
Complete Day 44 First