Skip to content

Commit 0604b3d

Browse files
committed
refactor: use Bootstrap classes to create an alert message that does not interrupt rendering on delete
1 parent 5513d3b commit 0604b3d

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎debugging/book-library/index.html‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ <h1>Library</h1>
6969
</div>
7070
</div>
7171

72+
<div id="message-container"></div>
73+
7274
<table class="table" id="display">
7375
<thead class="thead-dark">
7476
<tr>

‎debugging/book-library/script.js‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,21 @@ function render() {
9393
const deletedBook = myLibrary[i].title;
9494
myLibrary.splice(i, 1);
9595
render();
96-
alert(`You've deleted title: ${deletedBook}`);
96+
showMessage(`You've deleted title: ${deletedBook}`);
9797
});
9898
}
99+
100+
function showMessage(message) {
101+
const container = document.getElementById("message-container");
102+
container.innerHTML = "";
103+
const alert = document.createElement("div");
104+
alert.className = "alert alert-warning alert-dismissible fade show";
105+
alert.role = "alert";
106+
107+
alert.innerHTML = `${message} <button type="button" class="close" data-dismiss="alert" aria-label="Close">
108+
<span aria-hidden="true">&times;</span>
109+
</button>`;
110+
111+
container.appendChild(alert);
112+
}
99113
}

0 commit comments

Comments
 (0)