Home › Forums › JavaScript › Add and remove label to input field › Re: Add and remove label to input field
April 26, 2012 at 8:08 am
#101791
SgtLegend
Member
Mouse simple way is just to use the defaultValue property in the element object and some jQuery events.
$('.placeholder').each(function() {
$(this).on({
focus : function(e) {
if ($(this).val() === this.defaultValue) {
$(this).val('');
}
},
blur : function(e) {
if ($(this).val() !== this.defaultValue) {
$(this).val(this.defaultValue);
}
}
});
});
You can see it in action here