I have the following code which is supposed to target the #newsletter input, add the default text into it and then remove it when a user tabs / clicks into the input. However it doesn’t seem to work, and I get the following console error:
Uncaught SyntaxError: Unexpected end of input
Any ideas?
$(function() {
var defaultText = "Your email address";
$('#newsletter').val(defaultText).focus(function() {
if (this.value == defaultText) {
$(this).val('');
}
}).blur(function() {
if (this.value == '') {
$('#newsletter').val(defaultText);
}
});
You are missing closing brackets in your code:
By the way, the thing you try to implement is a placeholder for the form field. It is worth to read about
placeholderattribute in HTML5.