i have simple 2 text field. 1 normal text , have used datepicker. want clear placeholder onfocus , show again onblur following code using:
$('input,textarea').focus(function(){ $(this).data('placeholder',$(this).attr('placeholder')) console.log($(this).data('placeholder')); $(this).attr('placeholder',''); }); $('input,textarea').blur(function(){ console.log("adding "+$(this).data('placeholder')); $(this).attr('placeholder',$(this).data('placeholder')); }); for normal text working fine datepicker text field placeholder not coming after blur. there solution datepicker text field behave simple text field ?
try demo
two focus events triggered because of datepicker. second time triggers gets rid of property placeholder. check property before storing in .data(). should it
$('input,textarea').focus(function () { if ($(this).prop('placeholder')) { $(this).data('placeholder', $(this).prop('placeholder')) $(this).prop('placeholder', ''); } }); $('input,textarea').blur(function () { if (!$(this).prop('placeholder')) { $(this).prop('placeholder', $(this).data('placeholder')); } });
Comments
Post a Comment