Skip to content

Instantly share code, notes, and snippets.

@weskerfoot
Created December 27, 2015 05:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weskerfoot/c6c4c9d887cab4a9ef8c to your computer and use it in GitHub Desktop.
Save weskerfoot/c6c4c9d887cab4a9ef8c to your computer and use it in GitHub Desktop.
function genfocin(object, original) {
return function() {
var text = $(object).val();
if (text == original) {
$(object).val("");
}
};
}
function genfocout(object, original) {
return function() {
if ($(object).val() === "") {
$(object).val(original);
}
};
}
$("input").focusin(
function() {
var text = $(this).val();
var f = genfocin(this, text);
$(this).focusout(genfocout(this, text));
$(this).off("focusin");
$(this).focusin(f);
f();
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment