📝 Create a To-Do List App with Add/Delete/Complete Features in JavaScript
🚀 Introduction
If you're new to JavaScript and looking for a small yet practical project, a To-Do List App is perfect! You'll learn how to:
-
Add tasks
-
Mark them as complete
-
Delete tasks
-
Use HTML, CSS, and JavaScript together
Let’s dive in and build this app from scratch, step by step!
📁 1. Set Up Your Files
Create three files in your project folder:
-
index.html
-
style.css
-
script.js
🧱 2. HTML Structure (index.html
)
💡 Explanation:
-
#task-input
: Where the user types the task. -
#add-task-btn
: Button to add the task. -
#task-list
: Where the tasks will appear as a list.
🎨 3. Basic CSS Styling (style.css
)
💡 Explanation:
-
Clean, modern styling for the input, buttons, and task list.
-
.completed
adds a strikethrough style when a task is marked done.
⚙️ 4. JavaScript Functionality (script.js
)
💡 Explanation Step-by-Step:
-
addEventListener('click', ...)
: Runs when "Add Task" is clicked. -
trim()
: Removes spaces from start/end. -
createElement()
: Dynamically creates HTML elements (like buttons). -
classList.toggle('completed')
: Adds/removes the class to strike through text. -
removeChild()
: Deletes the task item from the list.
✅ Features Summary
Feature | Description |
---|---|
Add Task | User types a task and clicks "Add Task" |
Complete | Click “Complete” to mark task as done |
Delete | Click “Delete” to remove the task |
🧠 Final Tips
-
You can improve this app by saving tasks to localStorage.
-
Add a “clear all” button if needed.
-
Try learning frameworks like React after mastering this!