Inner HTML not working (SOLVED)

I am trying to make a script that will create a button however it doesn’t seem to be working, I followed a tutorial and it worked there but I can’t seem to recreate it in glitch.
This is what I have so far but it is not working

<!DOCTYPE html>
<html>
  <head>
    <script>
      document.body.innerHTML = '<button>New Button</button>';
    </script>
  </head>
  <body>
    
  </body>
</html>

Try use document.documentElement.innerHTML = '<button>New Button</button>';

Hey @Cohen_S_Erickson,

The body element you’re trying to call will not exist during the execution of the script. You can either move the <script> tag towards the closing <body> tag like this or trigger the script on window.onload()!

Hope this helps!

1 Like

Hey @Cohen_S_Erickson,
Do you have a project name or link that would help try fixing your issue?
Thanks

@YosefSinger
They asked this question 10 days ago.

but the threads not closed / marked as solved yet

@Realm_Melody, @YosefSinger has every right to continue relevant discussion in this thread, as @blubbll has rightly pointed out, because this thread has not been marked as solved or closed, by @Cohen_S_Erickson or any staff. And please do not have any irrelevant discussion in this thread!

Happy Glitching!

@blubbll, @Realm_Melody just, @khalby786 marked solved :wink:

1 Like