1👍
✅
Since you’ve got a nice id there, how about a hash table
var cache = {};
when needing to cache
cache[inputBox.attr('data-id')] = p.clone();
when you want to retrieve get the old version of the p back grab it from the hash table using the id.
if you want to store multiple versions of a p then use the hash table and have each element be an array implemented as a stack
cheers
0👍
I’ve edited a previous answer to fit this question:
When the p
is edited, make a clone of the element for the future, then replace the element with the copy later. By storing the full clone of the p
in its own data
attribute, it keeps its own history. You can do multiple “undo” clicks since it will continue to pop its own history from its data
.
$('.edit-phrase').on('click', function() {
var p = $(this).siblings('p');
p.data('my_clone', $(p).clone(true));
// continue with rest of the logic
});
$('.cancel-edit').on('click', function() {
var p = $(this).siblings('p');
p.replaceWith($(p).data('my_clone'));
// continue with rest of the logic
});
Documentation:
👤000
- [Answer]-In django which is the best way to make a slideshow of background images?
- [Answer]-Album app process in Django
- [Answer]-Celery chain tasks
Source:stackexchange.com