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

444
Views
ID assignment didn't worked. Error: Cannot read property of null

I have a doubt about the JavaScript element assignment. Here is my code for the "save" function. May I know why the code below shows error:

Cannot read properties of null (reading 'textContent')

let saveEl = document.getElementById("save-el");
function save(){
    let countStr = count + " - ";
    saveEl.textContent += countStr //This line doesn't worked.
    console.log(count);
}

But, when I removed the variable assignment saveEl as shown below, the code works well.

function save(){
    let countStr = count + " - ";
    document.getElementById("save-el").textContent += countStr;
    console.log(count);
}

Can anyone here explain to me why my code behave this way?

about 4 years ago · Juan Pablo Isaza
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!