# Executing Javascript in the custom HTML sidebar block

**URL:** https://meta.discourse.org/t/executing-javascript-in-the-custom-html-sidebar-block/325124
**Category:** Development
**Tags:** right-sidebar-blocks
**Created:** [September 5, 2024, 3:30pm UTC](https://meta.discourse.org/t/executing-javascript-in-the-custom-html-sidebar-block/325124 "2024-09-05T15:30:28Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![federatedRoss](https://avatars.discourse-cdn.com/v4/letter/f/46a35a/32.png) [@federatedRoss](https://meta.discourse.org/u/federatedRoss)
#### Post date: [September 5, 2024, 3:30pm UTC](https://meta.discourse.org/t/executing-javascript-in-the-custom-html-sidebar-block/325124/1 "2024-09-05T15:30:28Z")

</div>

I am using a custom-html block with content:

```plaintext
<div id="server-01-box"></div>
<script>
    fetch('//example.com/wp-admin/admin-ajax.php?action=aa-server-select&p=server-01')
        .then(function (response) {
            return response.text();
        })
        .then(function (body) {

            var server_parser = new DOMParser();
            var doc = server_parser.parseFromString(body, "text/html");
            var ad_container = doc.querySelector('div');

            document.querySelector('#server-01-box').innerHTML = ad_container.innerHTML;
        });
</script>

```

When I inspect the page HTML, its injected there. However, my ad doesn’t show up. Is there a trick to getting the JS to run from within the sideblock plugin?

---

<div class="post-metadata">

### Author: ![federatedRoss](https://avatars.discourse-cdn.com/v4/letter/f/46a35a/32.png) [@federatedRoss](https://meta.discourse.org/u/federatedRoss)
#### Post date: [September 5, 2024, 8:10pm UTC](https://meta.discourse.org/t/executing-javascript-in-the-custom-html-sidebar-block/325124/2 "2024-09-05T20:10:55Z")

</div>

I had to make a different custom theme component to get the JS to run, which is fine. Closing this out.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [October 5, 2024, 8:11pm UTC](https://meta.discourse.org/t/executing-javascript-in-the-custom-html-sidebar-block/325124/3 "2024-10-05T20:11:47Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
