Skip to content

Commit b65d201

Browse files
committed
To-Do List App: implimentation of a simple To-Do list app
1 parent 7150fc3 commit b65d201

4 files changed

Lines changed: 89 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# JavaScript-Projects
22
A list of beginner JavaScript projects
3+
# To-Do list App

To-Do List App/index.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<link rel="stylesheet" href="style.css">
7+
<title>To-Do List App</title>
8+
</head>
9+
<body>
10+
11+
<div class="container">
12+
<h1>To-Do List</h1>
13+
<input type="text" id="taskInput" placeholder="Add a new task">
14+
<button onclick="addTask()">Add</button>
15+
<ul id="taskList"></ul>
16+
</div>
17+
18+
<script src="script.js"></script>
19+
</body>
20+
</html>

To-Do List App/script.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Get DOM elements
2+
const taskInput = document.getElementById('taskInput');
3+
const taskList = document.getElementById('taskList');
4+
5+
// Function to add a new task
6+
function addTask() {
7+
const taskText = taskInput.value.trim();
8+
9+
if (taskText !== '') {
10+
// Create a new li element
11+
const newTask = document.createElement('li');
12+
newTask.textContent = taskText;
13+
14+
// Add click event to mark as completed
15+
newTask.addEventListener('click', function () {
16+
this.classList.toggle('completed');
17+
});
18+
19+
// Add context menu (right-click) event to delete
20+
newTask.addEventListener('contextmenu', function (event) {
21+
event.preventDefault();
22+
this.remove();
23+
});
24+
25+
// Append the new task to the list
26+
taskList.appendChild(newTask);
27+
28+
// Clear the input field
29+
taskInput.value = '';
30+
}
31+
}
32+

To-Do List App/style.css

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
body {
2+
font-family: 'Arial', sans-serif;
3+
background-color: #f4f4f4;
4+
margin: 0;
5+
padding: 0;
6+
display: flex;
7+
align-items: center;
8+
justify-content: center;
9+
height: 100vh;
10+
}
11+
12+
.container {
13+
background-color: #fff;
14+
padding: 20px;
15+
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
16+
border-radius: 8px;
17+
}
18+
19+
h1 {
20+
text-align: center;
21+
color: #333;
22+
}
23+
24+
ul {
25+
list-style-type: none;
26+
padding: 0;
27+
}
28+
29+
li {
30+
margin-bottom: 8px;
31+
}
32+
33+
.completed {
34+
text-decoration: line-through;
35+
color: #888;
36+
}

0 commit comments

Comments
 (0)