-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtodo-app.html
54 lines (44 loc) · 1.78 KB
/
todo-app.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple TODO App</title>
<style>
.completed {
text-decoration: line-through;
}
</style>
</head>
<body>
<h1>TODO App</h1>
This was written with ChatGPT and the prompt: <I>Write a TODO app in javascript where I can add items, then strike through items when I check them completed. It should only rely on DOM manipulation and be as simple as possible. Please provide the entire HTML.</I>
<input type="text" id="taskInput" placeholder="Add a new task">
<button onclick="addTask()">Add Task</button>
<ul id="taskList">
<!-- Tasks will be dynamically added here -->
</ul>
<script>
function addTask() {
var inputElement = document.getElementById('taskInput');
var taskListElement = document.getElementById('taskList');
// Get the task description from the input
var taskDescription = inputElement.value.trim();
// Check if the input is not empty
if (taskDescription !== '') {
// Create a new list item
var listItem = document.createElement('li');
listItem.textContent = taskDescription;
// Set up a click event listener to toggle the 'completed' class
listItem.addEventListener('click', function () {
listItem.classList.toggle('completed');
});
// Append the new list item to the task list
taskListElement.appendChild(listItem);
// Clear the input field
inputElement.value = '';
}
}
</script>
</body>
</html>