# How to actually define the action inside a widget

**URL:** <https://meta.discourse.org/t/how-to-actually-define-the-action-inside-a-widget/42081>\
**Category:** Development\
**Created:** [5 Abril, 2016 17:44 UTC](https://meta.discourse.org/t/how-to-actually-define-the-action-inside-a-widget/42081 "2016-04-05T17:44:37Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![stevenpslade](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stevenpslade/32/53550_2.png) [@stevenpslade](https://meta.discourse.org/u/stevenpslade)\
**Post date:** [5 Abril, 2016 17:44 UTC](https://meta.discourse.org/t/how-to-actually-define-the-action-inside-a-widget/42081/1 "2016-04-05T17:44:38Z")

</div>

Continuing the discussion from [A tour of how the Widget (Virtual DOM) code in Discourse works](https://meta.discourse.org/t/a-tour-of-how-the-widget-virtual-dom-code-in-discourse-works/40347):

In the `topic-map` widget I have the below code adding an action and class name to some text in the `topic-map`:

```
contents.push(h('li.secondary', [
      h('a', { className: 'top-answer-link',
              action: 'scrollTopAnswer'}, 'Jump to Top Answer')
    ]));

```

The class gets added fine and I see now errors. My issue however, is that I do not know where to define the action. Usually, I would define such an action in a component. As this is a widget, where should I place this code:

```
actions: {
    scrollTopAnswer: function() {
      alert('scrollTopAnswer');
      $('html,body').animate({scrollTop: ($('.most_liked_post').offset().top-140)}, 'slow');
    }
  }

```

---

_[View the full topic](https://meta.discourse.org/t/how-to-actually-define-the-action-inside-a-widget/42081)._
