diff --git a/booklist.js b/booklist.js index 020fbf5..2eb2d5b 100644 --- a/booklist.js +++ b/booklist.js @@ -20,18 +20,30 @@ const displayUsingApi = false; const body = $('#book-list') Object.keys(list).forEach((bookId) => { - console.log(bookId) - body.append(makeListItem(list[bookId])) + body.append(makeListItem(bookId, list[bookId])) }) } - function makeListItem(book) { + $('.remove-from-booklist').on('click', (event) => { + const target = $(event.target) + const bookId = target.parent().attr('id') + console.log(bookId) + removeBook(bookId) + location.reload() + }) + + function removeBook (id) { + const newlist = JSON.parse(localStorage.getItem('booklist')) + delete newlist[id] + localStorage.setItem('booklist', JSON.stringify(newlist)) + } + + function makeListItem (id, book) { const a = `

${book.title}

` - const li = `
  • ${a}Author: ${book.author}
  • ${a}Author: ${book.author} +
  • ` - console.log(li) return li } })(jQuery) // eslint-disable-line