Skip to content

Instantly share code, notes, and snippets.

@mdb
Created October 2, 2012 18:30
Show Gist options
  • Save mdb/3822096 to your computer and use it in GitHub Desktop.
Save mdb/3822096 to your computer and use it in GitHub Desktop.
var placeholderElems = $('[data-test]');
var placeholderAttr = 'data-test';
var placeholderClass = 'placeholder';
placeholderElems.focus(function() {
var input = $(this);
if (input.val() === input.attr(placeholderAttr)) {
input.val('');
input.removeClass(placeholderClass);
}
}).blur(function() {
var input = $(this);
if (input.val() === '' || input.val() === input.attr(placeholderAttr)) {
input.addClass(placeholderClass);
input.val(input.attr(placeholderAttr));
}
}).blur();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment