Skip to content

Instantly share code, notes, and snippets.

@safwanafridi
Last active February 8, 2024 08:58
Show Gist options
  • Save safwanafridi/fa8e880edf26ebf55837328a2d46466d to your computer and use it in GitHub Desktop.
Save safwanafridi/fa8e880edf26ebf55837328a2d46466d to your computer and use it in GitHub Desktop.
Open Elementor Popup using Javascript (Solution for showing 2nd elementor popup which is not opening on the page due to confliction )- In this senario popup will show when wpform is submitted and confimation message show up on page. You can change the trigger according to your need. You can add this code in the html block inside the elementor ed…
<script>
var Status = true;
var observer;
var config;
function runCodeWhenElementExists() {
setTimeout(() => {
// Check if the target element exists
if (document.querySelector("#wpforms-confirmation-2690") && Status) {
elementorProFrontend.modules.popup.showPopup({ id: 3641 });
Status = false;
}
}, 1000);
}
// Function to check if the target element exists
function checkElementExistence() {
const targetElement = document.getElementById('wpforms-confirmation-2690');
if (targetElement) {
// If the element exists, stop observing and run the code
observer.disconnect();
runCodeWhenElementExists();
}
}
// Create a MutationObserver with a callback function
observer = new MutationObserver(checkElementExistence);
// Define the configuration for the observer
config = { childList: true, subtree: true };
// Start observing changes in the document
observer.observe(document.body, config);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment