Pretty straightforward problem...

  1. On the dashboard, I click "New Widget".
  2. I select "My Custom Widget" type.
  3. A new instance of "My Custom Widget" appears on the dashboard, ready to be edited.

How can my widget be self-aware that it has just been created?

I need the widget to perform some very minor JS when it initially loads. Is there an existing JS event which would be triggered in this scenario?

1 Answer 1


It appears when a new widget is created it has a variety of classes (such as new and loading-new) that don't exist on established widgets:

class="widget new loading-new myplugin_mywidget flipped last"

It's also possible to add javascript to the widget settings file that gets rendered for your widgets settings. In the admittedly lame (but illustrative) example below, your new widget will get the text color of red, and after it is saved and the page reloads, no red color will be applied.

{% includejs %}
    $('.widget.new.myplugin_mywidget').css('color', 'red');
{% endincludejs %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.