how to show placeholder value after setting the value of input field as empty ""?

2.2k views Asked by At

I have input field with id = datepicker

 validationfails = true;

 if(validationfails)
 {
     $('#datepicker').val('');
     $('#datepicker').attr('placeholder','mm/dd/yyyy');
 }

I want to show the placeholder, if validation fails.

But the placeholder does not appear. When i press the backspace in the input field, it appears.

how to fix this.?

1

There are 1 answers

1
Rajiv007 On

Try:

$('#datepicker').attr('placeholder','mm/dd/yyyy').focus().blur();