Skip to content

Commit 97e07d0

Browse files
committed
lesson 9
1 parent 47fc064 commit 97e07d0

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

app.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
const bookList = document.querySelector('#book-list');
1+
const listItems = document.querySelectorAll('#book-list ul li');
22

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) => {
55

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);
1010

11-
console.log('all element children:');
12-
Array.from(bookList.children).forEach(function(node){
13-
console.log(node);
11+
});
1412
});
1513

16-
const titles = bookList.querySelectorAll('.name');
14+
// prevent default behaviour
15+
16+
const link = document.querySelector('#page-banner a');
1717

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');
2121
});

0 commit comments

Comments
 (0)