javascript - Undo action if "cancel" is pressed in response to confirm() -


i made quick list, can drag trash can (which removes it).

everything works when press "ok", , item gets removed told to. although if press "cancel" confirm popup, item shows in trash, , instead want go in list.

jsfiddle: http://jsfiddle.net/gdze8/2/

javascript:

   $( init )      function init() {     $(".contentitem").draggable({         revert: 'invalid'     });     $(".list4").droppable( {         accept: ".contentitem",          drop: function(event, ui) {             ui.draggable.hide();             if (confirm("are sure want delete?")){             ui.draggable.remove();              bottominfo ();         } else {             ui.draggable.show();         }         return false;         }     });     } 

you'll add confirm on draggable instead, reverting if confirm not confirmed etc :

$(".contentitem").draggable({     revert : function(event, ui) {         var state = confirm("are sure want delete?");         if (state) $(this).remove();         return !state;     } }); 

fiddle


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -