Skip to content

Instantly share code, notes, and snippets.

@felipelavinz
Created April 12, 2010 04:23
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 felipelavinz/363269 to your computer and use it in GitHub Desktop.
Save felipelavinz/363269 to your computer and use it in GitHub Desktop.
Simple jQuery plugin to set sample content on text inputs and automatically clean it on focus
/**
* A simple jQuery plugin to set sample content on text inputs
* and automatically clean it on focus
* @author Basilio Cáceres <bcaceres@ayerviernes.com>
* @author Felipe Lavín <flavin@ayerviernes.com>
*/
jQuery.fn.buscDef = function() {
var orVal = jQuery(this).val();
if ( jQuery.trim(orVal) != '' ) {
jQuery(this).data( 'defVal', orVal )
} else {
jQuery(this).data( 'defVal', 'Buscar' )
}
jQuery(this).blur(function() {
if ( jQuery(this).val() == '' ) {
jQuery(this).val( jQuery(this).data('defVal') )
}
}).focus(function() {
jQuery(this).select();
if ( jQuery(this).val() == jQuery(this).data('defVal') ) {
jQuery(this).val('');
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment