1
+ // let parent = document.getElementById('parent')
2
+ // let child2 = document.getElementById('child2')
3
+ // console.log('parent ==>',parent);
4
+ // console.log('parent with children ==> ',parent.children);
5
+
6
+ // console.log('child2 ==> ',child2);
7
+ // console.log('child2 parent ==> ',child2.parentElement);
8
+ // console.log('child2 previousSibling ==> ',child2.previousElementSibling);
9
+ // console.log('child2 nextSibling ==> ',child2.nextElementSibling);
10
+
11
+ let todo_input = document . getElementById ( 'todo_input' )
12
+ let add_todo_btn = document . getElementById ( 'add_todo_btn' )
13
+ let delete_all_todo_btn = document . getElementById ( 'delete_all_todo_btn' )
14
+ let todo_list = document . getElementById ( 'todo_list' )
15
+
16
+ add_todo_btn . addEventListener ( 'click' , function ( ) {
17
+ if ( ! todo_input . value ) return alert ( 'Please Add Todo' )
18
+
19
+ let list_item = `<li class="todo_item">
20
+ <span>${ todo_input . value } </span>
21
+ <i class="fa-solid fa-pen-to-square editIcon" onclick="edit_todo(this)" title="Edit"></i>
22
+ <i class="fa-solid fa-trash deleteIcon" onclick="delete_todo(this)" title="Delete"></i>
23
+ </li>`
24
+ todo_list . innerHTML += list_item
25
+
26
+ todo_input . value = ''
27
+ } )
28
+
29
+
30
+ function delete_todo ( element ) {
31
+ element . parentElement . remove ( )
32
+ // console.log('Delete == >', element.parentElement);
33
+
34
+ }
35
+
36
+ function edit_todo ( element ) {
37
+ let previousValue = element . previousElementSibling . innerText ;
38
+ let updatedValue = prompt ( 'Enter Updated Value' , previousValue )
39
+ element . previousElementSibling . innerText = updatedValue
40
+ console . log ( 'Edit == >' , element . parentElement ) ;
41
+
42
+ }
43
+
44
+ delete_all_todo_btn . addEventListener ( 'click' , function ( ) {
45
+ todo_list . innerHTML = ''
46
+ } )
0 commit comments