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

230
Views
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 answers
Answer question

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 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!