Return to Snippet

Revision: 27922
at June 26, 2010 23:18 by phil7085


Initial Code
$("body input").each(function(){
  if ($(this).val() == '') {
    $(this).val($(this).attr('title'));
    $(this).css('color','#ddd');
  } else if ($(this).val() == $(this).attr('title')) {
    $(this).css('color','#ddd');
  } else {
    $(this).css('color','#000');
  }
});

  // Set the value to the title attribute if blank or clear the value on focus if set to the title attribute

$("input").focus(function() {
  if ($(this).val() == $(this).attr('title')) {
    $(this).val('');
    $(this).css("color","#000");
  }
}).blur(function() {
  if ($(this).val() == '') {
    $(this).val($(this).attr('title'));
    $(this).css("color","#ddd");
  } else if ($(this).val() == $(this).attr('title')) {
    $(this).css("color","#ddd");
  }

});

Initial URL

                                

Initial Description

                                

Initial Title
Set or clear input values on load, focus & blur with jQuery

Initial Tags
jquery, load

Initial Language
JavaScript