Stack Stack - 1 year ago 69
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.

Answer Source

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" />