Skip to content

Commit d92c806

Browse files
Shaun PellingShaun Pelling
authored andcommitted
lesson 9 code
1 parent 8a62ef3 commit d92c806

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

app.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1-
const bookList = document.querySelector('#book-list');
1+
const list = document.querySelector('#book-list ul');
22

3-
console.log('#book-list next sibling:', bookList.nextSibling);
4-
console.log('#book-list next element sibling:', bookList.nextElementSibling);
5-
console.log('#book-list previous sibling:', bookList.previousSibling);
6-
console.log('#book-list previous element sibling:', bookList.previousElementSibling);
3+
list.addEventListener('click', (e) => {
4+
if(e.target.className == 'delete'){
5+
const li = e.target.parentElement;
6+
console.log('child element to remove:', li);
7+
console.log('parent element to remove child from:', li.parentElement);
8+
li.parentNode.removeChild(li);
9+
}
10+
});
711

8-
bookList.previousElementSibling.querySelector('p').innerHTML += '<br />Too cool for everyone else!';
12+
// prevent default behaviour
13+
14+
const link = document.querySelector('#page-banner a');
15+
16+
link.addEventListener('click', function(e){
17+
e.preventDefault();
18+
console.log('Navigation to', e.target.textContent, 'was prevented');
19+
});

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<div id="page-banner">
1212
<h1 class="title">Bookorama</h1>
1313
<p>Books for Ninjas</p>
14+
<a href="http://www.thenetninja.co.uk">Net Ninja Site</a>
1415
<form id="search-books">
1516
<input type="text" placeholder="Search books..." />
1617
</form>

0 commit comments

Comments
 (0)