# Executing js after DOM loaded

**URL:** https://meta.discourse.org/t/executing-js-after-dom-loaded/102958
**Category:** Support
**Created:** [November 28, 2018, 9:03am UTC](https://meta.discourse.org/t/executing-js-after-dom-loaded/102958 "2018-11-28T09:03:55Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![marina](https://avatars.discourse-cdn.com/v4/letter/m/f05b48/32.png) [@marina](https://meta.discourse.org/u/marina)
#### Post date: [November 29, 2018, 3:05am UTC](https://meta.discourse.org/t/executing-js-after-dom-loaded/102958/3 "2018-11-29T03:05:03Z")

</div>

Hi Simon,

I was actually trying to add a button to the topic pages, to be specific, .title-wrapper under #topic-title.

Thankfully, I have since found a work-around to this in another thread on meta.discourse. This approach allows the editing of specific posts in topics via the api method ‘addPostTransformCallback’. I’ve shared it below to help any others who face a similar issue.

> [@How do you force a script to refire on every page load in Discourse?](https://meta.discourse.org/t/how-do-you-force-a-script-to-refire-on-every-page-load-in-discourse/74856/16):
>
> I have been working on something that needs to be fired when entering a topic. I don’t know if this is overly complicated or the proper way to do it, but this is what I’ve found works well so far: \<script type="text/discourse-plugin" version="0.8.13"\> api.addPostTransformCallback((t) =\> { // post is topic post && element doesn't already exist if (t.post\_number === 1 && $("#test-id").length == 0) { $(function() { var testText = '\<h1 id="test-id"\>T…

A drawback of this though, is that it only works if u navigate to the topic page from another page within the forum. If I were to refresh the page, the edit (in my case, the button) does not show up. I am currently trying to solve that, and will share if I find a solution!

---

_[View the full topic](https://meta.discourse.org/t/executing-js-after-dom-loaded/102958)._
