javascript – Elementor stuck on loading when adding JS code

Question

I added the following code in a .js file to change a word every 2 seconds on my home page and it works well on the live site:

var words = ["Word 1","Word 2"];
var script = document.createElement('script');
script.type="text/javascript";
script.src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js";
document.body.appendChild(script);
jQuery(function () {    
    i = 0;
    setInterval(function(){ $('#change_title_text').fadeOut(function(){
        $(this).html(words[(i = (i + 1) % words.length)]).fadeIn();
      }); }, 2000)
});

The script is enqueued in my child theme as usual:

function custom_js_script_enqueue(){
    wp_enqueue_script('mycustomjs', CHILD_THEME_URI . '/assets/js/my-custom-js.js', array(), '1.0.0', true);
}
add_action('wp_enqueue_scripts', 'custom_js_script_enqueue');

However, when I try to go to Pages in the WP Admin area and then press “Edit with Elementor” it opens up a window with the E loading screen and stucks there forever. It doesn’t matter which page I try to load, it stucks on all pages. When commenting the code in the .js file I can edit with Elementor as usual.

What makes this code not compatible with Elementor? And is there a fix?

0
eligolf 1 month 2022-10-18T03:30:21-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse