Skip to content

Instantly share code, notes, and snippets.

@philhawksworth
Created January 6, 2012 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philhawksworth/1571430 to your computer and use it in GitHub Desktop.
Save philhawksworth/1571430 to your computer and use it in GitHub Desktop.
dynamicLabel = function($input, $label) {
// exit if either element isn't found
if ( !($input[0] && $label[0]) ) { return; }
function hideLabel() {
$label.hide();
}
function showLabelIfInputEmpty() {
!$input.val() && $label.show();
}
$input.keydown(hideLabel).focus(hideLabel).blur(showLabelIfInputEmpty);
showLabelIfInputEmpty();
}
}
var $inputelement = $('#yourinputelement'),
dynamicLabel( $inputelement, $inputelement.prev() );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment