Close an Elementor Popup After Its Form Is Sent
Closes the Elementor Pro popup a few seconds after the form inside it is submitted successfully, so visitors see the thank-you message and then return to the page.
Opens WPIDE on
Code
<script>
window.addEventListener('DOMContentLoaded', function () {
var delay = 2500; // Time to show the success message first.
if (!window.jQuery) { return; }
window.jQuery(document).on('submit_success', function (event) {
var form = event.target;
var modal = form && form.closest ? form.closest('.elementor-popup-modal') : null;
if (!modal) { return; }
setTimeout(function () {
var close = modal.querySelector('.dialog-close-button');
if (close) { close.click(); }
}, delay);
});
});
</script>
Notes
Change the delay (in milliseconds) at the top of the script.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.