I need it to clear the default input value on focus, and bring the value back if the value is empty on blur. Here is my current code:
$(document).ready(function() {
function toggleText(selector, value) {
$(selector).focus(function() {
if ($(this).val == value) {
$(this).val('');
}
});
$(selector).blur(function() {
if ($(this).val == '') {
$(this).val(value);
}
});
}
toggleText('input[name="first-name"]', 'First name...');
});
It’s
$(this).val(), not$(this).val:Edit:
But I think it’s better this way:
you can use
$(this).defaultValue()if you use this plugin.