Skip to content

Instantly share code, notes, and snippets.

@walterdavis
Created November 2, 2012 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walterdavis/a6e3a50f17e3c27c2073 to your computer and use it in GitHub Desktop.
Save walterdavis/a6e3a50f17e3c27c2073 to your computer and use it in GitHub Desktop.
$(document).ready(function() {
var _test = document.createElement('input');
if( ! ('placeholder' in _test) ){
//we are in the presence of a less-capable browser
$(document).on({
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.val() == input.attr('placeholder')) {
input.addClass('placeholder');
input.val(input.attr('placeholder'));
}
}
},"input[placeholder]");
$(document).on("submit","form",function() {
$(this).find('input[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