Task Management App

Step 1: Set Up Your Project

  1. Create a new folder for your project, e.g., task-manager.
  2. Inside this folder, create three files:
    • index.html
    • styles.css
    • script.js

Step 2: HTML Structure (index.html)

<!DOCTYPE html>
<html lang="en">
<head>
&lt;meta charset="UTF-8">
&lt;meta name="viewport" content="width=device-width, initial-scale=1.0">
&lt;link rel="stylesheet" href="styles.css">
&lt;title>Task Manager&lt;/title>
</head> <body>
&lt;div class="container">
    &lt;h1>Task Manager&lt;/h1>
    &lt;input type="text" id="taskInput" placeholder="Add a new task...">
    &lt;button id="addTaskButton">Add Task&lt;/button>
    &lt;ul id="taskList">&lt;/ul>
&lt;/div>
&lt;script src="script.js">&lt;/script>
</body> </html>

Step 3: Add Some Styles (styles.css)

body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
} .container {
max-width: 600px;
margin: auto;
background: white;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
} h1 {
text-align: center;
} input[type="text"] {
width: 70%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
} button {
padding: 10px;
border: none;
border-radius: 4px;
background-color: #28a745;
color: white;
cursor: pointer;
} button:hover {
background-color: #218838;
} ul {
list-style-type: none;
padding: 0;
} li {
display: flex;
justify-content: space-between;
padding: 10px;
border-bottom: 1px solid #ccc;
} li button {
background-color: #dc3545;
}

Step 4: Implement Functionality (script.js)

document.getElementById('addTaskButton').addEventListener('click', addTask);

function addTask() {
const taskInput = document.getElementById('taskInput');
const taskValue = taskInput.value.trim();
if (taskValue) {
    const taskList = document.getElementById('taskList');
    // Create list item
    const li = document.createElement('li');
    li.textContent = taskValue;
    // Create delete button
    const deleteButton = document.createElement('button');
    deleteButton.textContent = 'Delete';
    deleteButton.addEventListener('click', () => {
        taskList.removeChild(li);
    });
    li.appendChild(deleteButton);
    taskList.appendChild(li);
    // Clear input
    taskInput.value = '';
}
}

Step 5: Run Your App

  1. Open index.html in your web browser.
  2. You can now add tasks and delete them as needed.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *