Posted By

cesgra on 10/26/09


Tagged


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

ruhanirabin
cesgra
jirimelcak


Set/Clear Default Input Value


 / Published in: jQuery
 

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

  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. });

Report this snippet  

You need to login to post a comment.