fiddle http://jsfiddle.net/Q8F5u/3/
I have several divs , each of which has a delete button , to remove this particular div (in fact, I have to hide, not delete). After the divs have been deleted , I want to return them by pressing CTRL + Z.
I had some success in returning. The logic I used is that I pushed the deleted divs id onto the stack , and whenever I press ctrl + z, I popping the last hidden div identifier from the stack and using that identifier to return the hidden div.
Here's the javascript:
var deletedBlocks = []; $('.delete').on('click',function(){ var deletedid = $(this).closest('div[id^=block]').attr('id'); deletedBlocks.push(deletedid); $(this).closest('div[id^=block]').fadeOut(500); }); $('body').on('keydown',function(e){
The problem I am facing is that in my real application there is no such unique identifier for these divs. instead, they all have the same classes. How can I implement the same functionality if the div does not have unique identifiers.
source share