I have the following code:
// star/un-star
$('.starred').on("click", function(event) {
var inp = $(this)
var user_id = $(this).data('user_id');
var current_value = $(this).data('value');
var new_value = current_value == '0' ? 1 : 0;
$.post('/update_starred/', {'user_id': user_id, 'new_value': new_value}, function (response) {
inp.addClass('new')
});
});
I have noticed that I have to define var inp = $(this)
if I am to use that value within the post function. Why doesn't it keept the $(this)
value there? What is the value for $(this)
within the post function? Why?