| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ddbb0b5 commit 83b0916
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 1 | 1 | const list = document.querySelector('#book-list ul'); | |
| 2 | + const forms = document.forms; | ||
| 2 | 3 | ||
| 3 | 4 | // delete books | |
| 4 | 5 | list.addEventListener('click', (e) => { | |
@@ -8,17 +9,24 @@ list.addEventListener('click', (e) => { | |||
| 8 | 9 | } | |
| 9 | 10 | }); | |
| 10 | 11 | ||
| 11 | - const forms = document.forms; | ||
| 12 | - console.log(forms); | ||
| 13 | - console.log(forms['add-book']); | ||
| 14 | - | ||
| 15 | - Array.from(forms).forEach(function(form){ | ||
| 16 | - console.log(form); | ||
| 17 | - }); | ||
| 18 | - | ||
| 12 | + // add books | ||
| 19 | 13 | const addForm = forms['add-book']; | |
| 20 | 14 | addForm.addEventListener('submit', function(e){ | |
| 21 | 15 | e.preventDefault(); | |
| 16 | + | ||
| 17 | + // create elements | ||
| 22 | 18 | const value = addForm.querySelector('input[type="text"]').value; | |
| 23 | - console.log(value); | ||
| 19 | + const li = document.createElement('li'); | ||
| 20 | + const bookName = document.createElement('span'); | ||
| 21 | + const deleteBtn = document.createElement('span'); | ||
| 22 | + | ||
| 23 | + // add text content | ||
| 24 | + bookName.textContent = value; | ||
| 25 | + deleteBtn.textContent = 'delete'; | ||
| 26 | + | ||
| 27 | + // append to DOM | ||
| 28 | + li.appendChild(bookName); | ||
| 29 | + li.appendChild(deleteBtn); | ||
| 30 | + list.appendChild(li); | ||
| 31 | + //list.insertBefore(li, list.querySelector('li:first-child')); | ||
| 24 | 32 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments