0

I want to return the list object of the ul with the id "days" but it returns null object. What am i missing? Am relativly new to js so...

<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>Calender</title>
    <link rel="stylesheet" href="styles.css">
    <script src="app.js"></script>
  </head>

  <body>
    <div class="big">
      <div class="month">
        <ul>
          <li class="prev">1</li>
          <li class="next">2</li>
          <li>November<br><span>2020</span></li>
        </ul>
      </div>
      <ul class="weeks">
        <li>Mo</li>
        <li>Di</li>
        <li>Mi</li>
        <li>Do</li>
        <li>Fr</li>
        <li>Sa</li>
        <li>So</li>
      </ul>
      <ul class="days" id="days">
        <li>2</li>
      </ul>
    </div>
  </body>
</html>

JAVASCRIPT

var days = document.getElementById("days"); console.log(days); ... (would do some more logic with var days but cant because it returns null object for some reasons -_-)

OUTPUT

null + three "uncaught in promise" with {}

LIx
  • 11
  • 1
    Your script runs before the DOM is built. Move the ` – Pointy Dec 05 '20 at 00:46
  • Moving the script to the bottom of the body tag helped, thx. Never had that issue with other projects. – LIx Dec 05 '20 at 00:54

0 Answers0