sunnyujjawal commited on
Commit
450405b
·
1 Parent(s): 5afec05

Create index.html

Browse files

This code creates an HTML page with a textarea and a button for adding todo items, and an unordered list to display the todo items. It uses an array to store the todo items, and a function to add new items to the array and re-render the list when the button is clicked. The list items have checkboxes that can be used to mark the items as completed.

Files changed (1) hide show
  1. index.html +81 -0
index.html ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Todo App</title>
5
+ <style>
6
+ ul {
7
+ list-style: none;
8
+ padding: 0;
9
+ }
10
+ li {
11
+ display: flex;
12
+ align-items: center;
13
+ margin-top: 10px;
14
+ }
15
+ input[type="checkbox"] {
16
+ margin-right: 10px;
17
+ }
18
+ </style>
19
+ </head>
20
+ <body>
21
+ <h1>Todo App</h1>
22
+ <textarea id="todo-input"></textarea>
23
+ <button id="add-button">Add</button>
24
+ <ul id="todo-list"></ul>
25
+ <script>
26
+ // Array to store todo items
27
+ let todos = [];
28
+
29
+ // Get references to the DOM elements we need
30
+ const input = document.getElementById("todo-input");
31
+ const addButton = document.getElementById("add-button");
32
+ const list = document.getElementById("todo-list");
33
+
34
+ // Function to add a new todo item to the list
35
+ function addTodo() {
36
+ // Get the value of the textarea
37
+ const todoText = input.value;
38
+
39
+ // Add the new todo item to the array
40
+ todos.push({
41
+ text: todoText,
42
+ completed: false
43
+ });
44
+
45
+ // Clear the textarea
46
+ input.value = "";
47
+
48
+ // Re-render the list
49
+ renderTodos();
50
+ }
51
+
52
+ // Function to render the todo list
53
+ function renderTodos() {
54
+ // Clear the existing list
55
+ list.innerHTML = "";
56
+
57
+ // Loop through the todo items
58
+ for (const todo of todos) {
59
+ // Create a new list item element
60
+ const item = document.createElement("li");
61
+
62
+ // Add a checkbox to mark the todo as completed
63
+ const checkbox = document.createElement("input");
64
+ checkbox.type = "checkbox";
65
+ checkbox.checked = todo.completed;
66
+ item.appendChild(checkbox);
67
+
68
+ // Add the todo text to the list item
69
+ const text = document.createTextNode(todo.text);
70
+ item.appendChild(text);
71
+
72
+ // Append the list item to the list
73
+ list.appendChild(item);
74
+ }
75
+ }
76
+
77
+ // Add event listeners
78
+ addButton.addEventListener("click", addTodo);
79
+ </script>
80
+ </body>
81
+ </html>