Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lesson 10 #20

Open
wants to merge 3 commits into
base: lesson-10
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 43 additions & 6 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,46 @@
// const list = document.querySelector('#book-list ul');

// // delete books
// list.addEventListener('click', (e) => {
// if(e.target.className == 'delete'){
// const li = e.target.parentElement;
// li.parentNode.removeChild(li);
// }
// });



const list = document.querySelector('#book-list ul');

// delete books
list.addEventListener('click', (e) => {
if(e.target.className == 'delete'){
const li = e.target.parentElement;
li.parentNode.removeChild(li);
}
//delete books
list.addEventListener('click', function(e){
if(e.target.className == 'delete'){
const li = e.target.parentElement;
li.parentNode.removeChild(li);
}
});

const addForm = document.forms['add-book'];

addForm.addEventListener('submit', function (e) {
e.preventDefault();
const value = addForm.querySelector('input[type="text"]').value;

//create elements
const li = document.createElement('li'); //not input inside the dom yet, only created
const bookName = document.createElement('span');
const deleteBtn = document.createElement('span');

//append to Document
li.appendChild(bookName); //order does matter here
li.appendChild(deleteBtn);

//append the list to the unorderd list (ul) in the dom
list.appendChild(li) //the ul was selected using queryselected and asigned to list

//add textcontent to the bookName & deletebutton
deleteBtn.textContent = 'delete';
bookName.textContent = value;

deleteBtn.className = 'delete'
})