You can use the solution described in /a/5910/3635
Using a function called placeholder()
:
function placeholder(str){
$('input').css('color','#ccc');
$('input').val(str);
}
You should run it once when loading your page:
placeholder("Digite o produto desejado...");
And you should assign these events to your input, which would be ao clicar nele
(click) to clear its value, and ao sair dele
(Blur) place the placeholder again.
$('input').on("click", function () {
var ValorAnterior = $.cookie("ValorAtual") || "";
$(this).val(ValorAnterior);
});
$('input').on("blur", function () {
$.cookie("ValorAtual", $(this).val());
placeholder("Digite o produto desejado...");
});
But you have to include the plugin jQuery Cookie (if you want to use another form of cookie is your option).
Good solution @Zuul +1
– Guilherme Nascimento
+1 This is the best solution.
– Sampson