Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8012145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:14:26+00:00 2026-06-04T19:14:26+00:00

I have a <div id=populated> element on the page which receives dynamically created content,

  • 0

I have a <div id="populated"> element on the page which receives dynamically created content, including populated DIVs, text areas, input texts and check boxes. Moreover, there are some elements with addEventListener.

My question is: how to save this “populated” DIV and reload it when a user returns to the page?

What I’ve tried, by using localStorage:

  • Save the entire DIV as a serialised object (got tips from here). Problem: “Uncaught TypeError: Accessing selectionDirection on an input element that cannot have a selection.”

  • Save the entire DIV as innerHTML. Problems: 1) bind events are lost 2) already entered data in textareas/inputs is lost.

I can rebind the events, but parsing the DIV structure and storing/restoring .value for each element seemed too complicated.

I’m using “pure” JavaScript (no frameworks) and without AJAX. Any ideas, keywords?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T19:14:28+00:00Added an answer on June 4, 2026 at 7:14 pm

    It took some redesign, but I managed to solve the problem:

    1. The structure of the DIV is stored as innerHTML on onpageonload in localStorage.
    2. The values of the fields inside the DIV are serialised and stored in localStorage.
    3. The binding function is independent and can be called so it parses the whole DIV.

    On onbeforeunload the scrips goes through the DIV as saves the “inner HTML” and the values. While loading, the scripts checks if localStorage is empty: if not, populates the DIV, loads the values and rebind the events.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page in which I have a div. The content from that
I have a text input. A value is populated into it when the page
I have two divs. I would like to move/populate the text from div id
I have div which has three buttons as, <div id=buttons> <input id=preview class=ButtonStyle type=submit
I have a page which contains a div which must be resized via JS
I have one aspx page with some controls. Also i have one DIV which
I have a div which I want to populate with different html files from
I have a function which populates a div but includes js onclick. How ever
I have div container and inside couple divs with class demo like <div id='container'
I have div with vertical scroll bar. Div is being updated dynamically via ajax

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.