|
1 | | -const bookList = document.querySelector('#book-list'); |
| 1 | +const listItems = document.querySelectorAll('#book-list ul li'); |
2 | 2 |
|
3 | | -console.log('book list parent element:', bookList.parentElement); |
4 | | -console.log('book list parent node:', bookList.parentNode); |
| 3 | +Array.from(listItems).forEach(function(item){ |
| 4 | + item.addEventListener('click', (e) => { |
5 | 5 |
|
6 | | -console.log('all node children:'); |
7 | | -Array.from(bookList.childNodes).forEach(function(node){ |
8 | | - console.log(node); |
9 | | -}); |
| 6 | + const li = e.target.parentElement; |
| 7 | + console.log('child element to remove:', li); |
| 8 | + console.log('parent element to remove child from:', li.parentElement); |
| 9 | + li.parentNode.removeChild(li); |
10 | 10 |
|
11 | | -console.log('all element children:'); |
12 | | -Array.from(bookList.children).forEach(function(node){ |
13 | | - console.log(node); |
| 11 | + }); |
14 | 12 | }); |
15 | 13 |
|
16 | | -const titles = bookList.querySelectorAll('.name'); |
| 14 | +// prevent default behaviour |
| 15 | + |
| 16 | +const link = document.querySelector('#page-banner a'); |
17 | 17 |
|
18 | | -console.log('Book titles:'); |
19 | | -Array.from(titles).forEach(function(title){ |
20 | | - console.log(title.textContent); |
| 18 | +link.addEventListener('click', function(e){ |
| 19 | + e.preventDefault(); |
| 20 | + console.log('Navigation to', e.target.textContent, 'was prevented'); |
21 | 21 | }); |
0 commit comments