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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -