# Javascript in theme component only runs once?

**URL:** <https://meta.discourse.org/t/javascript-in-theme-component-only-runs-once/106202>\
**Category:** Product Support\
**Created:** [January 10, 2019, 3:52pm UTC](https://meta.discourse.org/t/javascript-in-theme-component-only-runs-once/106202 "2019-01-10T15:52:05Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)\
**Post date:** [January 10, 2019, 6:31pm UTC](https://meta.discourse.org/t/javascript-in-theme-component-only-runs-once/106202/4 "2019-01-10T18:31:50Z")

</div>

To use the api you will need to put the code inside a discourse-plugin block. (It’s still javascript, just with a sprinkling of Discourse added on top).

So something like:

```plaintext
<script type="text/discourse-plugin" version="0.2">
api.decorateCooked($elem => {
    refTagger.tag($elem[0]);
  });
</script>
```

---

_[View the full topic](https://meta.discourse.org/t/javascript-in-theme-component-only-runs-once/106202)._
