Close a bootstrap 5 modal after submit (if success) button

So I am assuming you are setting up the modal by using something like this?

var myModal = new bootstrap.Modal(document.getElementById('myModal'), options);

Here you are saying that the element id myModal is being used to setup a bootstrap.Modal object. If this is the case, you should then be able to simply call hide() directly on this object.

myModal.hide();

You might also be able to try out myModal.dispose() too.

Reference link below. Check out “Via JavaScript” heading…

1 Like