I'm using bootstrap 5 in my web app and the modal is not showing up.
Here is the HTML for my modal and for the button activating it:
<div
class="modal"
tabindex="-1"
id="newInstallModal"
aria-labelledby="settings"
>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Modal title</h5>
<button
type="button"
class="btn-close"
data-bs-dismiss="modal"
aria-label="Close"
></button>
</div>
<div class="modal-body">
<p>Modal body text goes here.</p>
</div>
<div class="modal-footer">
<button
type="button"
class="btn btn-secondary"
data-bs-dismiss="modal"
>
Close
</button>
<button type="button" class="btn btn-primary">
Save changes
</button>
</div>
</div>
</div>
</div>
<input
id="newInstallButton"
type="button"
class="btn btn-outline-primary"
value="New Install"
/>
And here is the typescript code assigning that bootstrap-5 provided to open the modal via js.
newInstallModal = <HTMLDivElement>document.getElementById("newInstallModal");
newInstallButton = <HTMLButtonElement>document.getElementById("newInstallButton");
newInstallModal.addEventListener("show.bs.modal", () => {
newInstallButton.focus();
})
Any help is good, because I'm done debugging for today.
Bootstrap-modal v5 usage :
Either you have to use data-
attributes:
<button type="button" data-bs-toggle="modal" data-bs-target="#newInstallModal">Launch modal</button>
OR via script:
var myModal = new bootstrap.Modal(document.getElementById('newInstallModal'), options)
EDIT: Also
myModal.addEventListener('shown.bs.modal', ...)
is just an eventlistener for when the modal is shown (after show transition ended)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.