Reputation: 9797
In a form, in the imput "text" how to have a color for the text value, before the user enters anything and another color for the text that the user enters?
(I don't mean input:focus, this is just when the user writes. I'm looking for a different color when he leaves the field also)
I have the example here: http://jsfiddle.net/JQSZE/
<form>
<input type="text" value="nom" />
</form>
Upvotes: 0
Views: 188
Reputation: 28753
you can also try like
$(document).ready(function(){
$("input").focus(function(){
(this).css("color", "green");
});
});
or smply try
$('input').css("color","green");
That's it
Upvotes: 0
Reputation: 2131
Use JavaScript focus and blur event.
jQuery(function(){
jQuery("input").focus(function(){
jQuery(this).css("color", "red");
}).blur(function(){
jQuery(this).css("color", "green");
});
});
Upvotes: 0
Reputation: 473
use jQuery to alter the class of the element once it leaves focus. You could easily add a few levels of complexity by checking if they've entered content before applying the class etc.
Here you go, here's a basic example:
http://jsfiddle.net/erinfreeman/q348G/
Upvotes: 2