jQuery - Add/Focus/Blur Input Value


/ Published in: jQuery
Save to your folder(s)

First value takes empty input values and adds 'Enter Value'.
Second snippet removes 'Enter Value' when input is focused.
Third snippet re-adds 'Enter Value' if the value is left blank.


Copy this code and paste it in your HTML
  1. $(function(){
  2.  
  3. $('input[type="text"]').each(function(){
  4. if(this.value==''){this.value='Enter Value'}
  5. });
  6.  
  7. $('input[type="text"]').focus(function(){
  8. if(this.value=='Enter Value'){this.value=''}
  9. });
  10.  
  11. $('input[type="text"]').blur(function(){
  12. if(this.value==''){this.value='Enter Value'}
  13. });
  14.  
  15. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.