# Javascript added to theme header returns $ is not defined

**URL:** <https://meta.discourse.org/t/javascript-added-to-theme-header-returns-is-not-defined/371370>\
**Category:** Development\
**Created:** [June 23, 2025, 5:26pm UTC](https://meta.discourse.org/t/javascript-added-to-theme-header-returns-is-not-defined/371370 "2025-06-23T17:26:36Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Alteras](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alteras/32/179824_2.png) [@Alteras](https://meta.discourse.org/u/Alteras)\
**Post date:** [June 24, 2025, 5:39am UTC](https://meta.discourse.org/t/javascript-added-to-theme-header-returns-is-not-defined/371370/4 "2025-06-24T05:39:54Z")

</div>

Since Discourse is an SPA, relying on the document “DOMContentLoaded” won’t be very helpful, since the document DOM is always “loaded” but the elements can be missing. Instead you’ll want to use Components as @merefield mentioned, or something like this: [How do you force a script to refire on every page load in Discourse? - #5 by simon](https://meta.discourse.org/t/how-do-you-force-a-script-to-refire-on-every-page-load-in-discourse/74856/5?silent=true). This way every time the page changes, your code can check for the element you’re trying to change.

---

_[View the full topic](https://meta.discourse.org/t/javascript-added-to-theme-header-returns-is-not-defined/371370)._
