-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscript.js
More file actions
25 lines (21 loc) · 729 Bytes
/
script.js
File metadata and controls
25 lines (21 loc) · 729 Bytes
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
function addBook() {
var titleInput = document.getElementById('title');
var authorInput = document.getElementById('author');
var title = titleInput.value;
var author = authorInput.value;
if (title && author) {
var bookList = document.getElementById('book-list');
var li = document.createElement('li');
li.innerHTML = `
<span>${title} by ${author}</span>
<button class="delete-btn" onclick="removeBook(this)">Delete</button>
`;
bookList.appendChild(li);
titleInput.value = '';
authorInput.value = '';
}
}
function removeBook(button) {
var li = button.parentElement;
li.remove();
}