Clear inputs that have default text
Sometimes the HTML5 placeholder attribute isn't ideal. In those situations, it's pretty each to add this JS to your page (make sure to also include jQuery) to cover all your text/email inputs
$("input[type='text'], input[type='email']").focus ->
content = @getAttribute("value")
$(this).val "" if $(this).val() is content
$("input[type='text'], input[type='email']").blur ->
content = @getAttribute("value")
$(this).val content if $(this).val() is ""
or if coffeescript isn't your thing
$("input[type='text'], input[type='email']").focus(function() {
var content;
content = this.getAttribute("value");
if ($(this).val() === content) {
return $(this).val("");
}
});
$("input[type='text'], input[type='email']").blur(function() {
var content;
content = this.getAttribute("value");
if ($(this).val() === "") {
return $(this).val(content);
}
});
Written by Devers
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Coffeescript
Authors
iam4x
94.17K
ericdfields
63.02K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#