# 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 Aprile 2016, 5:44pm 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:** 3

<div class="post-metadata">

**Author:** ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)\
**Post date:** [5 Aprile 2016, 7:20pm UTC](https://meta.discourse.org/t/how-to-actually-define-the-action-inside-a-widget/42081/3 "2016-04-05T19:20:46Z")

</div>

You can’t just add an action to an `<a>` element like that. You should create a new discourse widget for that:

```javascript
createWidget('jump-answer', {
  tagName: 'a.top-answer-link',
  click() {
    $('html,body').animate({scrollTop: ($('.most_liked_post').offset().top-140)}, 'slow');
  }
});

```

Then your contents would look like this instead:

```javascript
contents.push(h('li.secondary', this.attach('jump-answer')));

```

I should also mention that generally I prefer actions to be handled in controllers, but this is a bit of a weird case since you’re scrolling the page with jQuery. Normally you’d have the `click()` function call `sendWidgetAction` and have a method in the Controller or Route as @joebuhlig suggested.

---

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