Created
January 13, 2009 05:31
-
-
Save rmanalan/46340 to your computer and use it in GitHub Desktop.
jQuery plugin for the "input prompt" pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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