Using jQuery in widget development

You can hook into the DOMNodeInserted event to find out when your widget has been added to the side bar.

jQuery(document).on('DOMNodeInserted', '.widget-top', function () {
      alert(jQuery('.widget-title', this).text());
});

The code above will alert to any newly added widget. Once you’re hooked into the newly created widget, you can traverse it to find your specific class and take action, if it is your widget that was added.

Tested only with Firefox.

You can find out more information with this jQuery question https://stackoverflow.com/questions/15268661/jquery-on-create-event-for-dynamically-created-elements