Add a required
class to the required input fields
and then change your code like,
$( '#checkout-data input.required' ).each( function() {
$( this ).change( function() {
if( this.value.length < 1 ) {
$( this ).removeClass( 'valid' ).addClass( 'invalid' );
} else {
$( this ).removeClass( 'invalid' ).addClass( 'valid' );
}
});
});
Also, there is no need of $.each()
like,
$('#checkout-data input.required').change( function() {
if( this.value.length < 1 ) {
$( this ).removeClass( 'valid' ).addClass( 'invalid' );
} else {
$( this ).removeClass( 'invalid' ).addClass( 'valid' );
}
});