Set/Clear Default Input Value


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



Copy this code and paste it in your HTML
  1. $('.default-value').each(function() {
  2.  
  3. var default_value = this.value;
  4.  
  5. $(this).focus(function(){
  6. if(this.value == default_value) {
  7. this.value = '';
  8. }
  9. });
  10.  
  11. $(this).blur(function(){
  12. if(this.value == '') {
  13. this.value = default_value;
  14. }
  15. });
  16.  
  17. });

URL: http://css-tricks.com/snippets/jquery/setclear-default-input-value/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.