How do I cycle a JS function in WordPress? [closed]

Rather than trying to include jquery with your javascript, you should use wordpress to define jQuery as a dependency to your custom script.

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

you can read about all of the libraries available in wordpress here.

Your script should not include the jquery include and use jQuery directly rather than the $ shortcut.

The contents of my-custom-js.js should be as follows:

jQuery(function () {
    var messages = [],
        index = 0;

    messages.push('Word 1');
    messages.push('Word 2');

    function cycle() {
        jQuery('#change_title_text').html(messages[index]);
        index++;

        if (index === messages.length) {
            index = 0;
        }

        setTimeout(cycle, 2000);
    }

    cycle();
});

That will make sure jquery is loaded in the page before your script runs.

And then in Elementor at a HTML widget to the page with the html:

<div>
    <h1> Test sentence <span id="change_title_text">WordToChange</span></h1>
</div>

This runs correctly in my Elementor test page.

Alternatively…

you don’t really need to use jquery for this, just use vanilla javascript. use the DOMContentLoaded event. If you change your script to the following and it should work without any dependencies:

document.addEventListener("DOMContentLoaded", function() {
    var messages = [],
        index = 0,
        element = document.getElementById('change_title_text');


    messages.push('Word 1');
    messages.push('Word 2');

    function cycle() {
        element.innerHTML = messages[index];
        index++;

        if (index === messages.length) {
            index = 0;
        }

        setTimeout(cycle, 2000);
    }

    cycle();
});

Here it is working in a code pen: https://codepen.io/timrross/pen/dyeEoKE

No need for jquery.