Skip to content

Instantly share code, notes, and snippets.

@yuxhuang
Created May 8, 2013 16:13
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 yuxhuang/5541569 to your computer and use it in GitHub Desktop.
Save yuxhuang/5541569 to your computer and use it in GitHub Desktop.
placeholder.js
if (Modernizr && !Modernizr.input['placeholder']) {
$('[placeholder]:not(.placeholder_processed)').focus(function() {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
input.removeClass('placeholder');
}
}).blur(function() {
var input = $(this);
if (input.val() == '') {
input.addClass('placeholder');
input.val(input.attr('placeholder'));
}
}).blur()
.addClass('placeholder_processed')
.parents('form').submit(function() {
$(this).find('[placeholder]').each(function() {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment