Skip to content

Commit f9804bf

Browse files
committed
working on add li in toDoList.js.
1 parent e5df5c8 commit f9804bf

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

toDoList.js

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,15 @@ for (let i=0; i<deleteRef.length; i++){
2424

2525
let parentLi = deleteRef[i].parentNode
2626

27-
let parentItem=parentLi.parentNode
27+
let parentUl=parentLi.parentNode
2828

29-
parentItem.removeChild(parentLi)
30-
31-
//deleteRef[i].remove
32-
33-
//deleteRef[i].className='done'
29+
parentUl.removeChild(parentLi)
3430

3531
})
3632

3733
}
3834

39-
35+
let addElem = document.getElementsByClassName('add-item')
4036

4137
// If an 'Add' link is clicked, adds the item as a new list item with
4238
// addListItem function has been started to help you get going!
@@ -46,5 +42,40 @@ const addListItem = function(e) {
4642
const input = this.parentNode.getElementsByTagName('input')[0];
4743
const text = input.value; // use this text to create a new <li>
4844

45+
console.log(text)
46+
4947
// Finish function here
48+
49+
// need to access ul from div
50+
51+
const mainElem = this.parentNode.parentNode
52+
53+
const ulElem = mainElem.getElementsByTagName('ul')[0]
54+
55+
console.log(ulElem)
56+
57+
const liElem = document.createElement('li')
58+
59+
const spanElem = document.createElement('span')
60+
61+
spanElem.textContent=text
62+
63+
const aElem = document.createElement('a')
64+
65+
aElem.className="delete"
66+
67+
const link = document.createTextNode('Delete')
68+
69+
aElem.appendChild(link)
70+
71+
liElem.appendChild(spanElem)
72+
73+
liElem.appendChild(aElem)
74+
75+
ulElem.append(liElem)
76+
5077
};
78+
79+
addElem[0].addEventListener('click', addListItem)
80+
81+
// code can add li, but then breaks the delete functionality

0 commit comments

Comments
 (0)