# Possible to attach event handlers to widgets in theme/plugin?

**URL:** <https://meta.discourse.org/t/possible-to-attach-event-handlers-to-widgets-in-theme-plugin/166204>\
**Category:** Development\
**Created:** [October 4, 2020, 3:42pm UTC](https://meta.discourse.org/t/possible-to-attach-event-handlers-to-widgets-in-theme-plugin/166204 "2020-10-04T15:42:58Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![dchouinard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dchouinard/32/194662_2.png) [@dchouinard](https://meta.discourse.org/u/dchouinard)\
**Post date:** [October 4, 2020, 5:56pm UTC](https://meta.discourse.org/t/possible-to-attach-event-handlers-to-widgets-in-theme-plugin/166204/6 "2020-10-04T17:56:53Z")

</div>

Thanks all! Figured it out.

For others in the future looking to override event handlers for components, add the following to `javascripts/your-plugin-name/initializers/script-name-of-your-choice.js.es6`:

```
import { withPluginApi } from "discourse/lib/plugin-api";

export default {
  name: "custom-click-handler",

  initialize() {
    withPluginApi("0.8.20", (api) => {
      api.modifyClass("component:topic-list-item", {
        click(e) {
          ...
        }
      });
    });
  },
};

```

---

_[View the full topic](https://meta.discourse.org/t/possible-to-attach-event-handlers-to-widgets-in-theme-plugin/166204)._
