Code Snippet
When creating a popup in Elementor it can be given a button using the button widget for closing the popup. A simple link can also be created and JavaScript can be used to close it.
HTML and JavaScript
The following creates a simple link using the HTML a tag with a class of .close_sales_popup. Place this wherever you want the close link to appear.
<a class="close_sales_popup">Close Popup</a>
Then the following can be placed in the head of the document or better yet linked to and placed in an external .js file. The second line of the script looks for the link with the class .close_sales_popup, and on click, closes the open popup.
jQuery(function($) {
$(document).on('click','.close_sales_popup', function(event) {
elementorProFrontend.modules.popup.closePopup( {}, event);
});
});
WordPress Notes:
- All modifications to a theme or plugin should be made by creating a child theme and placing the changes there; changes made to the parent theme will be overwritten the next time it updates
We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.