Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

199
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda