jQuery replace with -


i have following html tag:

<a class="save action_btn" onclick="return false;">save</a> 

and code:

$(".save").live('click', function() {                             $.post("update.php", {uid: my_uid, save: "yes", mid: "<?php echo $mid; ?>"}, function(){                                     $(this).replacewith('<a class="action_btn x saved" onclick="return false;">saved</a>');                                 }                             );                  }); 

however, why not changing html tag?

it's cause erasing element 'itself'. need small delay, this:

$(".save").live('click', function() {     var $btn = $(this);     $.post("update.php", {uid: my_uid, save: "yes", mid: "<?php echo $mid; ?>"}, function(){                   settimeout(function(){            $btn.replacewith('<a class="action_btn x saved" onclick="return false;">saved</a>');           }, 100);      }); }); 

hope helps.

edit: delay (settimeout) necessary if ajax request synchronous. happening if there has been call $.ajaxsetup({async: true});


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -