Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Add and remove label to input field Re: Add and remove label to input field

#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