Executing Javascript in the custom HTML sidebar block

I am using a custom-html block with content:

<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?

1 Like

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

2 Likes

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