From e8d679c4efaf6642b324351321251944de72fa91 Mon Sep 17 00:00:00 2001 From: Shahid Afridi Date: Sat, 6 Jul 2024 21:30:20 +0500 Subject: [PATCH] finished project --- script.js | 33 ++++++++++++++++++++++++++++----- style.css | 7 +++++-- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/script.js b/script.js index d84c085..cb66b3a 100644 --- a/script.js +++ b/script.js @@ -29,6 +29,7 @@ let displayBtn = document.querySelector('.displayBtn'); let displayContainer = document.querySelector('.output-display'); + // event listener to the newbook button newBook.addEventListener('click', () => { @@ -86,6 +87,9 @@ newBook.addEventListener('click', () => { }); +// added an event listener to display button +displayBtn.addEventListener('click', display); + // function for displaying the books on the page function display() { myLibrary.forEach((item) => { @@ -101,24 +105,43 @@ function display() { }); } // its a helper function created for creating elements +// It's a helper function created for creating elements function createElements(container, e) { let title = document.createElement('p'); let author = document.createElement('p'); let pages = document.createElement('p'); let read = document.createElement('p'); - title.textContent = `Book Name : ${e.title}`; - author.textContent = `Written By : ${e.author}`; + // Setting content in elements + title.textContent = `Book Name: ${e.title}`; + author.textContent = `Written By: ${e.author}`; pages.textContent = `Contains ${e.pages} Pages`; - read.textContent = `Read ? : ${e.read}`; + read.textContent = `Read? : ${e.read}`; container.appendChild(title); container.appendChild(author); container.appendChild(pages); container.appendChild(read); + + let deletBtn = document.createElement('button'); + deletBtn.textContent = 'Delete'; + deletBtn.classList.add('delete-btn'); + container.appendChild(deletBtn); + + deletBtn.addEventListener('click', () => { + container.remove(); + displayBtn.style.display = 'block'; + }); +} + + +// function for deleting the book +// let delBtn = document.querySelector('.delete-btn'); +// delBtn. + +function deleteBook() { + } -// added an event listener to display button -displayBtn.addEventListener('click', display); diff --git a/style.css b/style.css index 28f65ad..0db3ca2 100644 --- a/style.css +++ b/style.css @@ -112,7 +112,8 @@ h6 { .newBook, .subBtn, -.displayBtn { +.displayBtn, +.delete-btn { width: auto; justify-self: center; background: none; @@ -124,10 +125,12 @@ h6 { font-family: roboto mono; font-weight: bold; transition: 0.8s all; + margin-top: 10px; } .newBook:hover, -.displayBtn:hover { +.displayBtn:hover, +.delete-btn:hover{ background: #e879f9; color: #0f172a; transition: 0.8s all;