I have a dynamically created list of inputs. I would like them to be:
1) red if they are required and empty.
2) yellow if they are not required but empty.
3) green if they contain a value.
I tried this:
<style>
.empty {
background: yellow;
}
.not-empty {
background: green;}
input:invalid {
background: red;
}
</style>
<script>
jQuery('input').blur(function(){
tmpval = jQuery('input').val();
if(tmpval == '') {
jQuery('input').addClass('empty');
jQuery('input').removeClass('not-empty');
} else {
jQuery('input').addClass('not-empty');
jQuery('input').removeClass('empty');
}
});
</script>