Eventi Click managed with jQuery is not triggered

Problem:
Greetings,
I added jquery.js and my script.js to the resources. In script.js I do this kind of call:
jQuery (’. button’). on (‘click’, function () {
alert (‘click’);
});

I have associated the “button” class to an element of the document, but the click event is not executed.
I verified that both script.js and jQuery.js are imported correctly by checking with the javascript console of Google Chrome.

Can anyone tell me where I’m wrong?
Thanks

Saola Animate version: 3.0.1

OS: Windows 10

Notes: Saola Animate Free Trial

Hi Aldo,

Script files in Resources are executed before creating scenes and elements.
So there’s no element with button class at that time.
You can change your script as follows to make it work:

jQuery(document).on('click', '.button', function () {
  alert('click');
});

Another way is defining functions in script files and call them in Saola Animate event handlers when scene elements are already created (e.g. in Scene Activate event)

Regards

A thousand thanks!
I am testing Saola Animate to find a valid alternative to the old “Adobe Edge Animate CC 2015”, which we are still using in my team. So far Saola Animate seems like a great product to me, congratulations!

1 Like

Glad to hear that you like Saola Animate :slightly_smiling_face:

I tried another equally good approach using this code:

jQuery(window).on ("load", function () {
        console.log ("ready!");

        jQuery('.button').on ('click', function () {

            alert ('click');
                
            });
 });

Hi Aldo,

Saola Animate creates elements dynamically, it doesn’t ensure that elements are created before window load event. So your approach may work for one project but not work for others.
A trivial example is a project with two scenes and the first scene has animations, the second scene will be created after window load event.

Regards

1 Like

Hi Toan,
Thank you for the clarification!

Regards