I\'m trying to figure out how to target every input(text and password) field on all forms on the page document to remove the default value when on focus with this single script:
That's because val
only returns the value of the first selected element, instead of storing the values, you can use defaultValue
property of the HTMLInputElement object.
$('input[type=text], input[type=password]').focus(function() {
if (this.value === this.defaultValue) $(this).val("");
}).blur(function(){
if (this.value.length === 0) this.value = this.defaultValue;
});
http://jsfiddle.net/MscgZ/