11import { initializeApp } from "https://www.gstatic.com/firebasejs/11.10.0/firebase-app.js" ;
2- import { getDocs , collection , addDoc , getFirestore , deleteDoc , doc } from "https://www.gstatic.com/firebasejs/11.10.0/firebase-firestore.js" ;
2+ import { getDocs , collection , addDoc , getFirestore , deleteDoc , doc , updateDoc } from "https://www.gstatic.com/firebasejs/11.10.0/firebase-firestore.js" ;
33
44const firebaseConfig = {
55 apiKey : "AIzaSyCmUHMVGUXGvNG1WBSyyqEbLMnw3VOjbYE" ,
@@ -18,7 +18,6 @@ const todoHandler = document.getElementById('addTodoBtn');
1818const todoInput = document . getElementById ( 'todoInput' ) ;
1919const main = document . getElementById ( 'main' ) ;
2020const ul = document . createElement ( 'ul' )
21- // const li = document.createElement('li')
2221ul . className = "todo-list"
2322ul . id = "todoList"
2423
@@ -66,39 +65,27 @@ function append(setId, todo) {
6665 <button id="${ setId } " class="btn-delete">Delete</button>
6766 </li>
6867 `
69- // console.log(ul);
70-
68+
7169 main . appendChild ( ul )
7270}
7371
7472
7573ul . addEventListener ( 'click' , ( e ) => {
7674 let btn = e . target . classList . contains ( "btn-edit" )
75+ const input = e . target . previousElementSibling ;
7776
7877 if ( btn ) {
79- const getElement = ul . children
80-
81- for ( var i = 0 ; i < getElement . length ; i ++ ) {
82- let getInp = getElement [ i ] . children [ 0 ] ;
83- let getEditBtn = getElement [ i ] . children [ 1 ]
84- // const moreGet = ul.children
85- // console.log(moreGet);
86-
87- if ( getInp . id === getEditBtn . id ) {
88- if ( moreGet . hasAttribute ( 'readonly' ) ) {
89- moreGet . removeAttribute ( 'readonly' )
90- moreGet . style . border = "1px solid blue"
91- } else {
92- moreGet . setAttribute ( 'readonly' , true )
93- moreGet . style . border = ""
94- }
95- }
96-
78+ if ( input . hasAttribute ( 'readonly' ) ) {
79+ input . removeAttribute ( 'readonly' )
80+ input . style . border = "1px solid #ccc"
81+ } else {
82+ input . setAttribute ( 'readonly' , true )
83+ input . style . border = ""
9784 }
98-
9985 }
10086
10187
88+
10289} )
10390
10491window . addEventListener ( "DOMContentLoaded" , fetching )
0 commit comments