Answer the question
In order to leave comments, you need to log in
How to save HTML along with current state?
Is it possible to save a block of HTML code along with its post-set data and attributes, for example, in HTML there is a form with a select element, the user selects an element from the list, then the javascript saves the entire form somewhere, and when the user returns to the form again, it is loaded along with selected items and user-entered data.
I tried using jQuery
to write and set the form via html() - the entered data is not saved. (
Is there a ready-made solution for saving HTML along with the state?
if the user decides to go back a step and change something very time consuming.
Answer the question
In order to leave comments, you need to log in
In the general case, you can't. The state of event handlers hung with addEventListener, for example, cannot be saved.
But if you only need form data, you can serialize it and then restore it.
Finally, it would be enough for me to have such a function that would write the HTML form with the values entered by the user into a string as is:
<div id="input_div">
<input type="text" name="text" value="">
</div>
//юзер вводит значение
//запускаем эту мегафункцию
var str = megafunc($('#input_div').html());
//str = '<input type="text" name="text" value="введенные юзером текст">'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question