/ Published in: jQuery
Clears input or search field on focus.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$(document).ready(function() { //attach function to input and make text grayed out on page load textReplacement($('#query').css("color", "#999")); }); // the function: function textReplacement(input){ //input focus text function var originalvalue = input.val(); input.focus( function(){ if( $.trim(input.val()) == originalvalue ){ input.val('').css("color", "#000"); } }); input.blur( function(){ if( $.trim(input.val()) == '' ){ input.val(originalvalue).css("color", "#999"); } }); }