Skip to content

Instantly share code, notes, and snippets.

@dbykadorov
Last active December 14, 2015 05:40
Show Gist options
  • Save dbykadorov/5037112 to your computer and use it in GitHub Desktop.
Save dbykadorov/5037112 to your computer and use it in GitHub Desktop.
Use from labels as fields hints
/**
* Label as hints magick.
*/
$.fn.labelHint = function() {
return this.each(function() {
var current = $(this);
var id = current.attr("id");
var label = $("label[for='" + id + "']:not(.error)");
var currentPosition = current.position();
if (current.val() == label.html() || current.val() == '') {
label.show();
} else {
label.hide();
}
// Events
label.click(function(){
label.hide();
});
current.click(function(){
label.hide();
});
current.focus(function(){
label.hide();
});
current.blur(function(){
if(current.val() == label.html() || current.val() == '') {
label.show();
}
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment