Stack Stack - 5 months ago 9x
HTML Question

How to set default value of input if value is empty? jQuery

Example, i have input where default value is 5.
But user remove it using backspace, so after that i want to set default value again.


Lets say your input is having a id test you can do like below

$('#test').on('change blur',function(){
      if($(this).val().trim().length === 0){
<script src=""></script>
<input id="test" type="text" value = "5" />