Skip to content

Instantly share code, notes, and snippets.

@voising
Last active December 18, 2015 13:18
Show Gist options
  • Save voising/5788460 to your computer and use it in GitHub Desktop.
Save voising/5788460 to your computer and use it in GitHub Desktop.
JQUERY : Ergonomics on forms #jsergo
// JS
$('.ergo input, .ergo textarea').each(function() {
var label = $(this).parent().find('label[for="' + this.id + '"]');
$(this).on('focus', function() {
label.addClass("focus");
});
$(this).on('keydown', function() {
label.addClass("hidden");
});
$(this).on('blur', function() {
label.removeClass("focus");
if (this.value === "")
label.removeClass("hidden");
});
if (this.value !== "")
label.addClass("hidden");
});
// CSS
/*
.focus {
color: #CCC;
}
.hidden {
visibility: hidden;
}
//*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment