In my code below, I am looping over each anchor link, getting the text value, firing it over ajax and getting a json response back. Its all working fine.
However, in the last stage of success, I am trying to add the response as a class to the anchor I am currently looping over with $(this)
$( ".field-name-field-staff .field-item a" ).each(function() {
var username = $(this).text();
var date = $(this).closest('td.views-field-field-event-date').find('span.date-display-single').text();
$.ajax({
type: 'GET',
url: "bookings/availability/data",
data: {
"username": username,
"date" : date
},
success: function (data) {
console.log(data);
console.log(data.css);
console.log(this);
$(this).addClass(data.css);
}
});
});
In the example above, In the console.logs, I get...
- An array of all data (works)
- A single value from that array (works)
- A full array dump of the ajax request object (NOT the anchor tag i want)
Can someone tell me how i go outside of the ajax and get the anchor object outside it?