jQuery default value


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



Copy this code and paste it in your HTML
  1. $('.default-value').each(function() {
  2. var default_value = this.value;
  3. $(this).css('color', '#666'); // this could be in the style sheet instead
  4. $(this).focus(function() {
  5. if(this.value == default_value) {
  6. this.value = '';
  7. $(this).css('color', '#333');
  8. }
  9. });
  10. $(this).blur(function() {
  11. if(this.value == '') {
  12. $(this).css('color', '#666');
  13. this.value = default_value;
  14. }
  15. });
  16. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.