I need help with altering my code to make my modal popup function properly.
Issue: I can only open my modal popup and cannot close it, once it’s open it’s stuck on the open screen
My code: Here is a screenshot off it , it can open but not close
And here is the related code like the dialog element etc.etc.
HTML
<!-- Modal Structure -->
<div id="myModal" class="modal">
<div class="modal-content">
<span class="close">×</span>
<p>Some text in the Modal..</p>
<button id="fullScreenBtn">Full Screen</button>
</div>
</div>
<button id="addPageButton">Add</button>
<button id="addPageButton">Add</button>
<div class="modal-content">
<button id="OpenBtn">Open</button>
<button id="closeBtn">Close</button>
<h2>Customize your page</h2>
<div class="modal-body">
<textarea placeholder="Enter your notes here..."></textarea>
</div>
</div>
</dialog>
CSS
.modal-content {
background-color: #fefefe;
padding: 20px;
border: 1px solid #888;
width: 80%; /* Could be more or less, depending on screen size */
max-width: 1000px; /* Max width for larger screens */
box-shadow: 0 5px 15px rgba(0,0,0,0.3);
border-radius: 8px;
margin: auto;
}
/* Full Screen Resize */
.full-screen {
width: 100% !important;
height: 100% !important;
top: 0 !important;
left: 0 !important;
order-radius: 0 !important;
}
}
</style>
JAVASCRIPT
<script>
// Get the elements
const openBtn = document.getElementById("addPageButton");
const modal = document.getElementById("myModal");
const closeBtn = document.getElementById("closeBtn");
const resizeButton = document.getElementById("resizeButton");
// Open the modal when the open button is clicked
openBtn.addEventListener("click", () => {
modal.showModal();
});
// Close the modal when the close button inside the modal is clicked
closeBtn.addEventListener("click", () => {
modal.close();
});
// Resize to full screen
resizeButton.addEventListener("click", () => {
const modalContent = document.querySelector(".modal-content");
if (modalContent.classList.contains("full-screen")) {
modalContent.classList.remove("full-screen");
resizeButton.textContent = "Resize to Full Screen";
} else {
modalContent.classList.add("full-screen");
resizeButton.textContent = "Exit Full Screen";
}
});
</script>
Please help! :0