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

261
Views
JavaScript Uncaught TypeError: myTable is null

I try to display elements of my database on my web page after loading it.
I fetch these elements using AJAX and it works fine.
The problem is when I try to assign container (myTable) to put there my elements (elementsOfDataBase).
I get an error 'JavaScript Uncaught TypeError: myTable is null' in my console.
I use DOM getElementById. ID 'my-Table' is unique.
Any idea what I'm doing wrong?

myJs.js

$.ajax({
  type: 'GET',
  url: 'myUrl/',
  success: function(response){
    console.log('success')
    let elementsOfDataBase = response.table
    const myTable = document.getElementById("my-Table");
    elementsOfDataBase.map(item => {
      const div = document.createElement('div')
      div.innerHTML += item.fields.item
      div.innerHTML += '<br>'
      myTable.appendChild(div);
    })
  },
  error: function (error){
    console.log('error')
  },
})

home.html

<div id="my-Table"></div>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

IMO you try to access the table before it's rendered. Try

$(document).ready(function(){
  //Your code
});
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!