I am using Jquery to remove a default value in an HTML input on focus.
However, if nothing is entered into the input I want the default value to re-appear.
To try and do this I have created:
$( "#contact input" ).each(function( index ) {
$(this).focus(function() {
var valvalue = $(this).val();
$(this).val('');
});
$(this).focusout(function() {
var newvalvalue = $(this).val();
if(newvalvalue == ''){
$(this).val('', valvalue);
}
});
});
The focus()
function works fine, but the variable valvalue
does not get picked up by the focusout
function.
Would anyone know a way to pass the valvalue
variable to that 2nd focusout
function?