How To Target All Input Text And Password Value?
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: $(d
Solution 1:
Get all the input type text value:
$("input:text").each(function() {
alert($(this).val());
});
Get all input type password value:
$("input:password").each(function() {
alert($(this).val());
});
Solution 2:
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;
});
Post a Comment for "How To Target All Input Text And Password Value?"