I have a div. Inside that div I have multiple elements. Some elements have the class 'myClass'. I also have a button. When clicked, a foreach loop runs for each element that has the class myClass within the div. An ajaxCall is send for each element. The text color of those elements are black by default. In case of success of the ajax call. I would like to remove the class classBlackFont and add the one classGreenFont. I tried the following code which is unfortunately not switching the classes eventhough the ajax call succeeded.
$("#someDiv .myClass").each(function() {
var ajaxData = "myAjaxData";
$.ajax({
type: "POST",
url: "somefile.php",
data: ajaxData,
success: function(data) {
$(this).removeClass('classBlackFont').addClass('classGreenFont');
}
});
});