I have this JQ code:
$("button").click(function() {
$.ajax({
url: 'ajax.php?act=complete&id=' + this.id,
success: function(data){
alert(data);
if (data == "Not good")
$(this).removeClass('button').addClass('red');
else
$(this).removeClass('button').addClass('green');
}
});
the alert(data) can alert only 2 things from the ajax.php file:
“Not good” and “Good”. (echo’s in PHP in the ajax.php file)
I decided to try and compare it to Not good and if it’s a match, change the button class to red.
The code doesn’t work. (if I put the class-change code before the IF, it does work).
What’s the problem here?