Last active
December 14, 2015 05:40
-
-
Save dbykadorov/5037112 to your computer and use it in GitHub Desktop.
Use from labels as fields hints
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
/** | |
* 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