JQuery confirmation (+ fancy)


/ Published in: jQuery
Save to your folder(s)



Copy this code and paste it in your HTML
  1. STANDARD
  2. ========
  3.  
  4. $('.ask-plain').click(function(e) {
  5.  
  6. e.preventDefault();
  7. thisHref = $(this).attr('href');
  8.  
  9. if(confirm('Are you sure')) {
  10. window.location = thisHref;
  11. }
  12.  
  13. });
  14.  
  15. FANCY
  16. ======
  17.  
  18. $('.ask').click(function(e) {
  19.  
  20. e.preventDefault();
  21. thisHref = $(this).attr('href');
  22.  
  23. if($(this).next('div.question').length <= 0)
  24. $(this).after('<div class="question">Are you sure?<br/> <span class="yes">Yes</span><span class="cancel">Cancel</span></div>');
  25.  
  26. $('.question').animate({opacity: 1}, 300);
  27.  
  28. $('.yes').live('click', function(){
  29. window.location = thisHref;
  30. });
  31.  
  32. $('.cancel').live('click', function(){
  33. $(this).parents('div.question').fadeOut(300, function() {
  34. $(this).remove();
  35. });
  36. });

URL: http://www.webstuffshare.com/2010/03/codesnippet-jquery-confirm-users-action/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.