# 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:** 1

<div class="post-metadata">

**Author:** ![jtbayly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jtbayly/32/119510_2.png) [@jtbayly](https://meta.discourse.org/u/jtbayly)\
**Post date:** [January 10, 2019, 3:52pm UTC](https://meta.discourse.org/t/javascript-in-theme-component-only-runs-once/106202/1 "2019-01-10T15:52:05Z")

</div>

Hi there, I’ve got a javascript snippet that I’m supposed to put before the closing body tag. It works, but just as described on [this very old topic](https://meta.discourse.org/t/what-is-the-best-way-to-inject-javascript-code/17485), it only seems to run on first page load. Because it is supposed to scan the contents of posts and create tooltips and links for certain phrases, it needs to run each time new content is loaded.

Because of the _huge_ combination of potential strings (any Bible passage reference) to be linked, it is impossible to use a solution such as the [Auto-Linkify Words](https://meta.discourse.org/t/linkify-words-in-post/82193) plugin.

Apparently this sort of thing is possible to pull off in a theme component, as linkify does, but in my case the snippet just loads the actual javascript file from an external server and tells it to run. Anybody have any idea how I can get this working on content loaded via ajax?

Here’s the javascript snippet:

```plaintext
    <script>
	var refTagger = {
		settings: {
			bibleVersion: "NASB",			
			socialSharing: []
		}
	};
	(function(d, t) {
		var g = d.createElement(t), s = d.getElementsByTagName(t)[0];
		g.src = "//api.reftagger.com/v2/RefTagger.js";
		s.parentNode.insertBefore(g, s);
	}(document, "script"));
    </script>

```

---

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