Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

77
Vistas
Is it possible to save a div in session storage and retrieve/append it?

I am making a website which creates some divs when a form is submitted, the problem is that these divs disappear when the form is resubmitted. Would it be possible to save these divs in sessionStorage so that when the form is resubmitted they can be appended back where they were? Something like this:

for (i = 0; i <= children.length - 1; i++) {
    var selectedrow = children[i];
    sessionStorage.setItem(i, selectedrow);
}
sessionStorage.setItem('total', children.length)

for (n = 0; n < sessionStorage.getItem('total'); n++) {
    const rowid = sessionStorage.getItem('n');
    selected.appendChild(rowid);
}

This code gives the following error Error

So is there a way I can actually do this?

7 months ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Have a look at DOMParser(), this object creates a new DOM document from a string.

To use it, you instantiate a new instance. Then you use the parseFromString() method to convert your string into a new document element. The method accepts the string as it’s first argument. Set the second argument to text/html.

var stringToHTML = function (str) {
    var parser = new DOMParser();
    var doc = parser.parseFromString(str, 'text/html');
    return doc.body;
};

stringToHTML('<your html returned from session storage>');
7 months 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 empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.