title: Uncaught TypeError: Cannot read properties of null (reading 'appendChild')
body: <p>I'm trying to insert a new Div and an img inside that div via JS. I made a Class that i will user later on with a function inside that should be called to use that function and insert the image. When doing this i constantly get <code>Uncaught TypeError: Cannot read properties of null (reading 'appendChild')</code> HTML and JS below:</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang=&quot;en&quot;&gt;
  &lt;meta charset=&quot;UTF-8&quot;&gt;
  &lt;title&gt;Actividad 3&lt;/title&gt;
  &lt;script type=&quot;text/javascript&quot; src=&quot;actividad3.js&quot;&gt;&lt;/script&gt;
  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width,initial-scale=1&quot;&gt;
  &lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;
  
  
  &lt;body &gt;
  &lt;h2&gt;EXTRAS DISPONIBLES&lt;/h2&gt;
  
      
  &lt;/body&gt;
  &lt;/html&gt;
  
  </code></pre>
  <p>JS</p>
  <pre><code>class extra {
      precio = &quot;10€&quot;;
      url = &quot;concha_azul.jpeg&quot;;
      constructor(precio, url) {
          this.precio = precio;
          this.url = url;
      }
      getHTML = function () {
          console.log(&quot;hello&quot;);
          var newDiv = document.createElement(&quot;div&quot;);
          newDiv.id = &quot;x&quot;;
          var div = document.getElementById(&quot;x&quot;);
          var img = document.createElement(&quot;img&quot;);
          img.src = &quot;concha_azul.jpeg&quot;;
  
          div.appendChild(img); 
      }
      
  }
  
  let miExtra = new extra();
  miExtra.getHTML();
  </code></pre>