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

200
Views
JavaScript, getElementById from local storage returns blank page with element on it

I'm trying to get data from localStorage, but my whole app becomes a blank screen with the data I'm trying to retrieve at the top of it.

I was reading online that I should add return false; to the function where I'm getting the data, but it doesn't help.

Code:

window.localStorage.setItem('test',
JSON.stringify({ scoreId: window.scoreId, streak: 0, testMe: 'testing, testing'})
);

const retrieveStreak = () => {
const test = JSON.parse(window.localStorage.getItem('test'));
const testStreak = document.getElementById('root').textContent = test.testMe;
console.log(testStreak);
return false;
}

Otherwise the data is saving successfully, and when retrieving it I also get it printed out in console.log, but the issue is that my whole app goes blank.

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

0

Deleted document.getElementById('root').textContent = from the code and now it works as expected

Thank Quentin for the tip

window.localStorage.setItem('test',
JSON.stringify({ scoreId: window.scoreId, streak: 0, testMe: 'testing, testing'})
);

const retrieveStreak = () => {
const test = JSON.parse(window.localStorage.getItem('test'));
const testStreak = document.getElementById('root').textContent = test.testMe;
console.log(testStreak);
return false;
}
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!