Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
Uncaught TypeError: Cannot read properties of null (reading 'style') [JS]

expected outcome: div "test" should be shown,

but error in console: "Uncaught TypeError: Cannot read properties of null (reading 'style')"

It already worked in the past but somehow it stopped working (I guess it stopped when splitting html, css and js in different files but im not sure)

My simplified source code:

index.html

<link rel="stylesheet" type="text/css" href="./main.css">
<script src="./main.js"></script>
<div id="test"> test </div>

main.css

#test{display: none}

main.js

 //(agree not defined so typeof(agree) == undefined)
 if (agree == undefined) { document.getElementById("test").style.display = "block"; }

what did I do wrong? or is it actualy the splitted file / external js/css

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Just use one of the methods:

  1. Add defer attribute
<link rel="stylesheet" type="text/css" href="./main.css">
<script defer src="./main.js"></script>
<div id="test"> test </div>
  1. Add script after div
<link rel="stylesheet" type="text/css" href="./main.css">
<div id="test"> test </div>
<script src="./main.js"></script>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!