Hello, I have a container div where several spans are draggable. I want to build an UNDO function for them. I am thinking at:
- when span attributes are changed (position, css) the script detects a DOM change
- the DOM change is stored via HTML5 localStorage
- When the UNDO function is called the last version of the DOM replace the current.
I have the basic localStorage code that will record the last DOM state:
$('#undo').live('click', function() {
var testObject = $('#container').html();
// Put the object into storage
localStorage.setItem('testObject', JSON.stringify(testObject));
// Retrieve the object from storage
var retrievedObject = localStorage.getItem('testObject');
alert( retrievedObject );
// retrievedObject should now replace the current DOM
});
});
right now this code just takes the current DOM and stores it. The alert is displaying what is in the localstorage. I should probably try to store several DOM states and put them in variables. After that, on each UNDO, to delete one variable... I am not sure that this is the way to do it.
Any inputs on this one? Thank you