'Form submit event is caught only if the code inserted consule rather than rendered on the server

jQuery(document).ready(function () {
    window.mySuccessFunction = function ($form) {
        alert("hi"); // Breakpoint.
    }

    
    $('.js-form-proccess').each(function () {
        $(this).data('success-callback', 'window.mySuccessFunction');
    });
}

There is a site made on Tilda.

This is the documentation: https://help-ru.tilda.cc/tips/javascript#rec6022508

When this code is inserted on the page, it doesn't work. Neither a modal window springs up, nor the interpreter stops at the breakpoint.

The problem is that if I copy this code and paste it in the console, it will work.

Could you tell me what may be the reason for such behaviour (events are subdued or the form was not rendered in due time or something)? And how to cope with this problem?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source