Skip to content

Instantly share code, notes, and snippets.

@fullsailor
Created September 24, 2010 17: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 fullsailor/595691 to your computer and use it in GitHub Desktop.
Save fullsailor/595691 to your computer and use it in GitHub Desktop.
jQuery(function($) {
// Fallback functionality for HTML5 input placeholder text
if (document.createElement('input').placeholder === undefined) {
$('input[placeholder]').prompted_text_input().blur();
}
});
jQuery.fn.prompted_text_input = function () {
return this.each(function() {
$(this)
.bind('blur', function () {
$this = $(this);
if($this.val() === '') {
$this
.val($this.attr('placeholder') || '')
.addClass('showing_prompt')
;
}
})
.bind('focus', function () {
$this = $(this);
if($this.val() === $this.attr('placeholder')) {
$this
.val('')
.removeClass('showing_prompt')
;
}
})
;
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment