I’m using jquery for a cross browser solution for an input placeholder but I don’t understand how to set a global variable for $(this) so that I can use it in the second part of this two part function. I first grab the value of the input and store it as $value but I need to use it again in the second function to replace the empty value with it. How do I do this? Something I should have mentioned is this needs to work for multiple text inputs in one form.
$(document).ready( function() {
$('input[type=text]')
.on('focus', function(){
var $this = $(this);
var $value = $(this).val();
globalVar = $value;
if($this.val() == $value){
$this.val('');
}
})
.on('blur', function(){
var $this = $(this);
if($this.val() == ''){
$this.val($value);
}
});
});
you could use a variable outside the scope of those two functions.. but it would probably better to use the
dataas a storage place:Edit:
added this: