Videos
After reading your answers, I noticed my mistake:
...
<div class="modal modal-content" id="seeModal">
<span class="close">×</span>
...
was supposed to be the same as
...
<div class="modal modal-content" id="hearModal">
<span class="close" id="close">×</span>
...
Fixing that and defining var close inside the function did the trick! Thank you!
In your code, you have id="close" for the close button in the "hearModal". However, when you're trying to select it in JavaScript, you're using const closeModal = document.getElementById("close");, which only selects the first element with the ID of "close", which is associated with the "hearModal" close button.
Check the below example, this may get you some idea.
const seeModal = document.getElementById("seeModal");
const hearModal = document.getElementById("hearModal");
const seeBtn = document.getElementById("seeBtn");
const hearBtn = document.getElementById("hearBtn");
const seeCloseModal = document.getElementById("seeClose");
const hearCloseModal = document.getElementById("hearClose");
const closeSeeModal = function () {
seeModal.style.display = "none";
};
const closeHearModal = function () {
hearModal.style.display = "none";
};
seeBtn.addEventListener("click", function () {
seeModal.style.display = "block";
});
hearBtn.addEventListener("click", function () {
hearModal.style.display = "block";
});
seeCloseModal.addEventListener("click", closeSeeModal);
hearCloseModal.addEventListener("click", closeHearModal);
.modal {
display: none; /* Hidden by default */
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0,0,0,0.5);
}
.modal-content {
background-color: #fff;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
max-width: 600px;
}
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Modal Example</title>
</head>
<body>
<!-- Trigger/Open The Modal -->
<p><button id="seeBtn" type="button">SEE</button></p>
<p><button id="hearBtn" type="button">HEAR</button></p>
<!-- The Modal -->
<div class="modal" id="seeModal">
<div class="modal-content">
<span class="close" id="seeClose">×</span>
<p>See their profile</p>
<p>Additional content...</p>
</div>
</div>
<div class="modal" id="hearModal">
<div class="modal-content">
<span class="close" id="hearClose">×</span>
<p>Hear their Stories</p>
<p>Additional content...</p>
</div>
</div>
</body>
</html>
The code you are executing i.e. $('body').append("modal.html");, will simply add a text node 'modal.html' as a child of body. It will not load the 'modal.html' file from your server.
Assuming, that the modal.html file is served by your server at <hostname>/modal.html, your JS should be something like this:
$.get('/modal.html', function(content) {
$('body').append(content);
});
$.get('/modal.html') loads the 'modal.html' file from your server. The callback function is executed when the file is loaded from server, at which point you can append the returned content to 'body'.
PS: To show the modal you'd need to pass a string 'show' to .modal function. eg. $("#dlgModal").modal('show')
I mixed some calls up. I had to use load(), but doing that in my body, would remove everything that was already there, so I added a container:
$('body').append("<div id='messageboxContainer'></div>");
$('#messageboxContainer').load("modal.html");