0

I'm Trying To Create New Elements To Show Info For A Discord Bot List Im Making

  var btn = document.createElement("BUTTON");
  btn.innerHTML = "Try It"
  document.body.appendChild(btn);
<html>
  <head>
    <title>Squox Bot List</title>
        <script src="script.js"></script>
    <link href="style.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Vast+Shadow&display=swap" rel="stylesheet">
  </head>
  <body>
        <div class="line">
            <a target="_blank" href="https://discord.gg/TUD9WPE"><img src="images/Discord.png" width="50" height="auto"></a>
            <h1>Squox Bots</h1><br>
      </div>
<div id="div1">
<p id="p1">This is a paragraph.</p>
<p id="p2">This is another paragraph.</p>
</div>
  </body>
</html>

I Keep Getting Cannot read property 'appendChild' of null
When I Look At Old Questions From Stackoverflow, I Get The Same Error

So Anyone With Help Thank You

shawn
  • 42
  • 7

1 Answers1

0

I Fixed My Error By Making The JS A Function Ran When The Body Loads

shawn
  • 42
  • 7