Skip to content

Instantly share code, notes, and snippets.

@yoko
Created April 22, 2011 10:53
Show Gist options
  • Save yoko/936444 to your computer and use it in GitHub Desktop.
Save yoko/936444 to your computer and use it in GitHub Desktop.
(function($) {
$.support.placeholder = 'placeholder' in document.createElement('input');
$.fn.placeholder = function() {
var supported = $.support.placeholder;
if (!supported) {
this.each(function() {
var input = $('input[placeholder]', this);
if (input.length) {
var placeholder = $('<div class="placeholder">' + input.attr('placeholder') + '</div>')
.insertBefore(input)
.click(function() {
placeholder.hide();
input.focus();
});
input
.blur(function() {
if (!input.val()) {
placeholder.show();
}
})
.blur();
}
});
}
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment