/ Published in: JavaScript

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$("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"); } });
Comments
