A little dab'll do ya
Code Snippets
$("#s")
.val("Search...")
.css("color", "#ccc")
.focus(function(){
$(this).css("color", "black");
if ($(this).val() == "Search...") {
$(this).val("");
}
})
.blur(function(){
$(this).css("color", "#ccc");
if ($(this).val() == "") {
$(this).val("Search...");
}
});
- Set value of field to "Search..."
- When field comes into focus, set color to black.
- If value is default, remove it.
- When field goes out of focus, set color back to light gray.
- If value is empty, put back default value
I would like the text to only go back to grey if it is the default ‘search…’ text..
blur(function(){if ($(this).val() == "") {
$(this).css("color", "#ccc");
$(this).val("Search...");
}
i think this one is better, it will work for all textboxes and it uses the in page value instead of declaring the value in jquery.
swap_val = [];$(".swap").each(function(i){
swap_val[i] = $(this).val();
$(this).focusin(function(){
if ($(this).val() == swap_val[i]) {
$(this).val("");
}
}).focusout(function(){
if ($.trim($(this).val()) == "") {
$(this).val(swap_val[i]);
}
});
});
This is perfect and has made my day! Thanks.
why it doesn’t work for me?
this is my page
please take a look, I’m going crazy
http://www.athenarestauri.com/prova-jquery-2.html