taskForm.addEventListener('submit', function(e) {
e.preventDefault();
const taskText = taskInput.value.trim();
if (taskText !== '') {
addTask(taskText);
taskInput.value = '';
}
});
taskList.addEventListener('click', function(e) {
if (e.target.classList.contains('delete')) {
e.target.parentElement.remove();
} else if (e.target.tagName === 'LI') {
e.target.classList.toggle('completed');
}
});
function addTask(taskText) {
const li = document.createElement('li');
li.appendChild(document.createTextNode(taskText));
const deleteBtn = document.createElement('button');
deleteBtn.className = 'delete';
deleteBtn.appendChild(document.createTextNode('X'));
li.appendChild(deleteBtn);
taskList.appendChild(li);
}
}); body { font-family: Arial, sans-serif; background: #f4f4f4; display: flex; justify-content: center; align-items: center; height: 100vh; }
.container { background: white; padding: 20px; border-radius: 5px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); width: 300px; }
h1 { text-align: center; }
form { display: flex; justify-content: space-between; margin-bottom: 20px; }
form input { flex: 1; padding: 10px; border: 1px solid #ddd; border-radius: 3px; }
form button { padding: 10px; background: #5cb85c; color: white; border: none; border-radius: 3px; cursor: pointer; }
form button:hover { background: #4cae4c; }
ul { list-style: none; padding: 0; }
ul li { background: #f9f9f9; margin-bottom: 10px; padding: 10px; border: 1px solid #ddd; border-radius: 3px; display: flex; justify-content: space-between; }
ul li.completed { text-decoration: line-through; color: #888; }
ul li button { background: #d9534f; color: white; border: none; border-radius: 3px; cursor: pointer; }
ul li button:hover { background: #c9302c; }