Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove placeholder on focus [duplicate]

I made this simple function to add placeholder in browsers that do not support it:

DEMO

The question is: How can I add to that function the possibility to remove the placeholder when the user click inside it?

like image 372
FrancescoMussi Avatar asked Sep 11 '25 02:09

FrancescoMussi


1 Answers

Try to use removeAttr() like,

$('input,textarea').focus(function(){
   $(this).removeAttr('placeholder');
});

Demo

To get the placeholder value again on blur() try this,

$('input,textarea').focus(function(){
   $(this).data('placeholder',$(this).attr('placeholder'))
          .attr('placeholder','');
}).blur(function(){
   $(this).attr('placeholder',$(this).data('placeholder'));
});

Demo 1

like image 80
Rohan Kumar Avatar answered Sep 12 '25 17:09

Rohan Kumar