When I use the line below, $(this) inside my jQuery function (example below) it works great.
$(this).closest('.item').children('h3').children('a').text('UPDATED');
However, inside the same function I try to then move it within a function of success: area of $.ajax and it no longer works. I’ve checked that the success function works with an alert.
Is there a way to preserve the scope of $(this) inside $.ajax?
Thanks in advance for any suggestions.
Problem area:
success : function(msg){
$(this).closest('.item').children('h3').children('a').text('UPDATED');
},
Yes, use context:
Look up the context option about 14% down the page.