Plugin's scripts load before widget

Hi, I am developing a new plugin. When I create jQuery events to bind them with html elements I get an error, it is because the script loads before my widget gets rendered. How can I solve this problem?

I already made a setInterval and stopped it when some element of my widget gets rendered, and all the functionality works great; the problem is that when I click again (on my widget’s menu option), the widget reloads but the script stops working.

There must be a piwik way to solve this, but I can’t find the solution.

Please, help.

Thank you very much.