# Functie uitvoeren nadat de DOM is geladen (didRender, didInsertElement en decorateCooked werken niet)

**URL:** https://meta.discourse.org/t/run-function-after-dom-has-loaded-didrender-didinsertelement-and-decoratecooked-are-not-working/214802
**Category:** Development
**Created:** [13 januari 2022 om 22:10 UTC](https://meta.discourse.org/t/run-function-after-dom-has-loaded-didrender-didinsertelement-and-decoratecooked-are-not-working/214802 "2022-01-13T22:10:04Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![JQ331](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@JQ331](https://meta.discourse.org/u/JQ331)
#### Post date: [13 januari 2022 om 22:10 UTC](https://meta.discourse.org/t/run-function-after-dom-has-loaded-didrender-didinsertelement-and-decoratecooked-are-not-working/214802/1 "2022-01-13T22:10:04Z")

</div>

Hi. I am trying to evaluate a div on the topic show page. In order to do so, I need to run a function after the dom on the topic show page is done loading.

In normal javascript, i’d run “window.onload = function()…” for this. However, this onload function doesn’t seem to work when the topic is navigated to from within the site.

How can I run the function after the dom is fully loaded?

* * *

I have tried the following, and none of them seem to work:

```plaintext
withPluginApi("0.11.1", api => {
    api.modifyClass('component:topic-title', {
          didRender: function(){ //tried "didInsertElement" as well
                  //run function--still runs before all the divs have loaded
           } 
      }), 
     api.decorateCookedElement(function() {
           //run function--still runs before all the divs have loaded.
    })
})

```

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [13 januari 2022 om 22:37 UTC](https://meta.discourse.org/t/run-function-after-dom-has-loaded-didrender-didinsertelement-and-decoratecooked-are-not-working/214802/2 "2022-01-13T22:37:32Z")

</div>

I believe you have to do it by Component event. Why do you care anyway? Perhaps pick a Component deep into the tree, as it were. One of the ‘leaves’.

“Dom fully loaded” doesn’t really make as much sense in a Single Page Application, as everything is dynamic?

In short, it sounds like you are on the right track already. What issue is this causing? Why do you have to have _all_ the divs loaded?

What do you mean by “evaluate a div” exactly? Perhaps there is another way to go about what you are doing?

---

<div class="post-metadata">

### Author: ![JQ331](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@JQ331](https://meta.discourse.org/u/JQ331)
#### Post date: [14 januari 2022 om 12:52 UTC](https://meta.discourse.org/t/run-function-after-dom-has-loaded-didrender-didinsertelement-and-decoratecooked-are-not-working/214802/3 "2022-01-14T12:52:31Z")

</div>

I want to change the text of the div or, in some cases, remove it from the view.

Good point about the component I am choosing–that could be the reason for the trouble, that the component I am choosing is loading before some of the divs, and that I could try components that might load later. Thanks.
