Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rmanalan
Created January 13, 2009 05:31
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 rmanalan/46340 to your computer and use it in GitHub Desktop.
Save rmanalan/46340 to your computer and use it in GitHub Desktop.
jQuery plugin for the "input prompt" pattern
// Extracted from http://github.com/madrobby/prototype_helpers/tree/master/defaultValueActsAsHint
// Accepts JQuery elem as input for hiding/unhiding related elements.
$.fn.defaultValueActsAsHint = function(elems){
this.get(0)._default = this.attr('title');
return $(this).focus(function(){
if(this._default != this.value) return;
this.value = '';
$(this).removeClass('quiet');
elems.each(function(){$(this).show()});
}).blur(function(){
if(this.value.trim() != '') return;
this.value = this._default;
$(this).addClass('quiet');
elems.each(function(){$(this).hide()});
}).addClass('quiet').val(this.attr('title'));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment