ws3f
ws3f
Application
Objective
Build a to-do list where users can add and remove tasks.
Code to Type
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>To-Do List</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="todo-container">
<h1>My To-Do List</h1>
<input type="text" id="taskInput" placeholder="Ente
r a new task">
<button id="addTask">Add Task</button>
<ul id="taskList"></ul>
</div>
<script src="script.js"></script>
</body>
</html>
styles.css
body {
background-color: #f4f4f4;
font-family: Arial, sans-serif;
}
#taskInput {
width: 70%;
padding: 10px;
font-size: 1em;
border: 1px solid #ccc;
border-radius: 5px;
}
#addTask {
padding: 10px 20px;
font-size: 1em;
border: none;
background-color: #28a745;
color: white;
border-radius: 5px;
cursor: pointer;
}
#addTask:hover {
background-color: #218838;
}
#taskList {
list-style: none;
padding: 0;
margin-top: 20px;
}
.delete-btn {
background-color: #dc3545;
border: none;
color: white;
padding: 5px 10px;
border-radius: 5px;
cursor: pointer;
}
.delete-btn:hover {
background-color: #c82333;
}
script.js
addTaskButton.addEventListener('click', () => {
const taskText = taskInput.value.trim();
if (taskText === '') return;
const li = document.createElement('li');
li.textContent = taskText;
const deleteBtn = document.createElement('button');
deleteBtn.textContent = 'Delete';
deleteBtn.classList.add('delete-btn');
deleteBtn.addEventListener('click', () => {
Key Points
Manipulates the DOM to add and remove list items.
Employs CSS Flexbox for aligning task items and delete buttons.