Created
January 6, 2012 16:57
-
-
Save philhawksworth/1571430 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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