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

229
Views
Uncaught TypeError: Cannot read properties of null (reading 'style')

I, trying to make a div clickable so it will be redirected to a different document or site but got that error. However, it works with the old way of using the onclick as an attribute inside the element.

var examscol = document.getElementById("exam-col1");
function examCol() {
  return window.location.assign("https://www.w3schools.com")
}

examscol.addEventListener("click", examCol);

Any suggestions on why it isn't working with this way ?

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

0

1. Problem

The problem is that the id of the element is not exam-col1. When I change the id of the element to exam-col I get the following error [1]:

Error
{
  "message": "Uncaught TypeError: Cannot read properties of null (reading 'addEventListener')",
}
2. Hint

The frame cannot be displayed when the URL's X-Frame-Options field is set to SAMEORIGIN. The X-Frame-Options HTTP response header can be used to indicate whether or not a browser should be allowed to render a page in a <frame>, <iframe>, <embed> or <object> [2]. That's why I changed the targeted URL.

/* If there is no item with an id of "exam-col1" on the page, you will get a "null" error. */
var examscol = document.getElementById("exam-col1");

function examCol() {
 return window.location.assign("https://www.wikipedia.com")
}

examscol.addEventListener("click", examCol);
.clickable {
  display: inline;
  cursor: pointer;
  padding: 5px;
  border: 1px solid red;
}
<!-- Note that the id of the item is "exam-col1". -->
<div id="exam-col1" class="clickable">Open</div>


1 - JavaScript TypeError: Cannot read property 'style' of null
2 - X-Frame-Options

about 4 years ago · Juan Pablo Isaza Report

0

I thinks nothing wrong in this code it something else referring to some style error .you can check your html if its ok and also show you code to insure whats the problem. Its would be pleasure

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!