File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+
2+ .container {
3+
4+ display : flex;
5+ flex-direction : column;
6+ align-items : center;
7+ justify-content : center;
8+ height : 80% ;
9+ width : 75% ;
10+ background-color : # f0f0f0 ;
11+ border : 1px solid black;
12+
13+ }
14+
15+ h1 {
16+ color : blue
17+
18+
19+ }
20+
Original file line number Diff line number Diff line change 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+ < title > ToDo App</ title >
7+ < link rel ="stylesheet " href ="/css/todo.css ">
8+ </ head >
9+ < body >
10+ < div class ="container ">
11+ < h1 > ToDo List</ h1 >
12+ < form id ="todo-form ">
13+ < input type ="text " id ="todo-input " placeholder ="Add a new task... " required >
14+ < button type ="submit " onclick ="AddTask() "> Add</ button >
15+ </ form >
16+ < ul id ="todo-list "> </ ul >
17+ </ div >
18+
19+ < script src ="/js/todo.js "> </ script >
20+
21+ </ body >
22+ </ html >
Original file line number Diff line number Diff line change 1+
2+ const inputbox = document . getElementById ( "todo-input" ) ;
3+
4+ const list = document . getElementById ( "todo-list" ) ;
5+
6+ function AddTask ( ) {
7+
8+ if ( inputbox . value === "" ) {
9+ alert ( "Please enter a task." ) ;
10+ return ;
11+ } else {
12+ const li = document . createElement ( "li" ) ;
13+ li . innerHTML = inputbox . value + " <button class='delete' onclick='DeleteTask(this)'>Delete</button>" ;
14+ list . appendChild ( li ) ;
15+
16+ }
17+ inputbox . value = "" ; // Clear the input box after adding the task
18+
19+
20+
21+ }
22+
23+
24+ function DeleteTask ( button ) {
25+ button . parentElement . remove ( ) ; // This removes the <li> element
26+ }
You can’t perform that action at this time.
0 commit comments