Skip to content

Instantly share code, notes, and snippets.

@higeorange
Created February 2, 2009 11:20
Show Gist options
  • Save higeorange/56885 to your computer and use it in GitHub Desktop.
Save higeorange/56885 to your computer and use it in GitHub Desktop.
(function($) {
$.fn.preInput = function(txt, options) {
var default_options = {
class_name: 'pre-input'
};
options = $.merge(default_options, options || {});
return this.each(function(){
if(typeof this.value == 'undefined') return;
var elm = $(this);
elm.val(txt)
elm.addClass(options.class_name)
elm.focus(function(){
if(elm.val() == txt) {
elm.removeClass(options.class_name)
elm.val('');
}
});
elm.blur(function(){
if(elm.val() == '') {
elm.addClass(options.class_name)
elm.val(txt)
}
});
});
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment