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

389
Vistas
how to manage [object HTMLDivElement] and get its content?

I have saved an array in local storage and trying to use it but when I console.log the localstorage.getitem it returns
[object HTMLDivElement] I have tried to use .innerhtml or [...] on it but they didn't work. Btw, since it's an array, I have to use JSON.stringify(movieWatchlistArray):

 localStorage.setItem("key",JSON.stringify(movieWatchlistArray))
 let str =localStorage.getItem("key")
 console.log(JSON.parse(str) )

But when I do this, it will return an empty object inside an array while when I console.log the original array it's fine so I tried to do it without JSON part, it worked but returns a string of
[object HTMLDivElement]

 localStorage.setItem("key",movieWatchlistArray)  
 let str =localStorage.getItem("key")
 console.log(str)

So how to get the content of [object HTMLDivElement] I have used .innerhtml but it says can't use .innerHTML on undefined .

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

when you trying to save an element in localstorage you should save the .outerHTML of it, not the element itself. although it's not recommended to save the whole HTML in local storage instead save the data as an object and use it in js to render the HTML. so in this case it will be :

movieWatchlistArray.unshift(document.querySelector(`.movie--${moviePageNumber-1}`).outerHTML) 
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