-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
41 lines (33 loc) · 1.38 KB
/
script.js
File metadata and controls
41 lines (33 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var overlay = document.querySelector(".overlay")
var popupbox = document.querySelector(".popupbox")
var btn = document.getElementById("add-popup")
btn.addEventListener("click",function(){
overlay.style.display = "block"
popupbox.style.display= "block"
})
var cancelpopup = document.getElementById("cancel-book") //JS variable name should not contain unnderscore
cancelpopup.addEventListener("click",function(event){
event.preventDefault()
overlay.style.display = "none"
popupbox.style.display= "none"
})
var container = document.querySelector(".container")
var addbook = document.getElementById("add-book")
var booktitleinput = document.getElementById("book-title-input")
var bookauthor = document.getElementById("book-author-input")
var bookdescription = document.getElementById("para")
addbook.addEventListener("click",function(event){
event.preventDefault();
var div = document.createElement("div")
div.setAttribute("class","book-container")
div.innerHTML = ` <h2> ${booktitleinput.value}</h2>
<h5>${bookauthor.value}</h5>
<p>${bookdescription.value}</p>
<button onclick="deletebook(event)">Delete</button>`
container.append(div)
overlay.style.display = "none"
popupbox.style.display= "none"
})
function deletebook(event){
event.target.parentElement.remove();
}