javascript - Inserting a Confirm/Cancel pop-up into JQuery - CSS Issue -


i still quite new jquery , trying make simple pop-up message confirm delete, want table row turn red during process.

i found code seems sweet, short, , simple.

$(document).ready(function(){     $('.confirm').click(function(){         var answer = confirm("are sure want delete item?");         if (answer){             return true;         } else {             return false;         }     }); }); 

from: http://brettgregson.com/programming/how-to-make-a-are-you-sure-pop-up-with-jquery/138

and "attempting" add onto current deletefunction(), still pretty new jquery , having "bugs" it.

my deletefunction (no confirmation - color updating works fine)

function deletefunction(element) {         var newid = $(element).closest("td").find("span.id").text();         $(element).closest("tr").css('background-color', 'red');         $.post(                 '@url.action("customdelete", "movie")',                  {                      'id': newid                  },                 function (data) { },                 "json"             );         $(element).closest("tr").hide();     } 

my insertion of confirmation box works, not update tr background color, nor revert color default upon cancellation.

function deletefunction(element) {     var newid = $(element).closest("td").find("span.id").text();     $(element).closest("tr").css('background-color', 'red');      $(document).ready(function () {          var answer = confirm("are sure want delete item?");         if (answer) {             $.post(         '@url.action("customdelete", "movie")',         {             'id': newid         },         function (data) { },         "json"         );             $(element).closest("tr").remove();             return true;         } else {             $(element).closest("tr").css('background-color', 'default');             return false;         }     });   } 

if explain why css color not being touched until after confirmation box appears (or why not remove color after cancel pressed) appreciated.

i've created jsfiddle you: working sample. clearing color, should use css('background-color', 'initial'). highlighting - should highlight, sample does. if not help, feel free reveal html markup, issue there


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -