To run Javascript code from a custom widget in an Elementor popup you will need to use this code snippet.
We made the code snippet available directly from the widget creator for ease of usage.
- Click the Javascript Tab
- Click the show code examples link on the bottom.
- Click the “JS Code Snippets” link on the right sidebar
- Click the “Code Wrapper for Elementor Popup”
Note:
Your code should start from this function. Make sure you have some element with a dynamic ID {{uc_id}} in the HTML code tab.
For example: <div id=”{{uc_id}}”></div>
For your convenience you can also copy the code below.
jQuery(document).ready(function(){
function {{uc_id}}_start(){
/* Put code here */
console.log("This code works!");
}if(jQuery("#{{uc_id}}").length) {{uc_id}}_start(); else
jQuery( document ).on( 'elementor/popup/show', () => { if(jQuery("#{{uc_id}}").length) {{uc_id}}_start();});
});