jquery - After $.post in .done() how do I use $(this)? -
i want function update text in div on completion of ajax $.post call. works fine except in .done call $(this) no longer looking @ element listing to.
any appreciated.
//add or remove time time off $(".timechange").on("click", function(){ var id = $(this).val(); var timecommand = $(this).attr("data-command"); var currenttime = $(this).siblings('.timehold').text(); $.post("humanresourcefunctions.php/", { command : "modifyleavetime", employee : id, addsubtract : timecommand, time : currenttime }).done(function(data) { $(this).siblings('.timehold').text(data); }); });
the problem in the last operation, $(this).siblings('.timehold').text(data);
you need cache reference it.
$(".timechange").on("click", function(){ var $this = $(this); //cache
then later on..
.done(function(data) { $this.siblings('.timehold').text(data); //note $this not $(this); });
Comments
Post a Comment