Changing the button class by the received data

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?

Comment out the alert, and use curly braces around your conditional, ie if(condition){function}else{otherFunction}

Also, trim the value of data before comparing - PHP might be putting some whitespace in there, somewhere. :slight_smile: