The reason $this is not working in the Ajax success function is because the context of $this changes within the success function. When the Ajax request is made, the success function is executed in a different scope, and the this keyword refers to the Ajax object instead of the clicked element.

To access the clicked element within the success function, you can store the reference to $this in a variable outside of the Ajax call, and then use that variable within the success function. Here's an example:

$(document).on('click', '.qq_add_to_cart_list', function() { var $this = $(this); var item_id = $this.attr("data_child");

$.ajax({ // Ajax options here

success: function(response) {
  // Use $this here
}

}); })

$documentonclick qq_add_to_cart_list function var item_id = $thisattrdata_child; $ajax$this not working in ajax success why