You can simplify the code to:
$('#agree').change(function(){
$('#submit')[ this.checked ? 'addClass' : 'removeClass' ]('enabled').prop('disabled', !this.checked);
});
So if #agree
is checked, call addClass('enabled')
and set prop('disabled', false)
, else removeClass('enabled')
and set prop('disabled', true)
.
You also need to change your CSS so that if #agree
has the enabled
class, it has precedence over the id
selector:
#submit.enabled {
background-color: #CC2EFA;
}