Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

234
Visualizações
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?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

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>');
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda