I need to change the class of the input based on text value. When the value is empty it should be default, when there is a value it should change the class to inputtext.
<style>
.inputnotext{ background:#ddd; }
.inputtext{ background:transparent } /* when their is text */
</style>
<form>
<input class="inputnotext" type="text" name="firstname" /><br />
<input class="inputnotext" type="text" name="lastname" />
</form>
<script>
/* script to write ??? */
</script>
This is a javascript which you can use:
jsFiddle example
Up-to-date version (using event listener and classList):
jsFiddle example