Skip to content

Instantly share code, notes, and snippets.

@marciobarrios
Created October 28, 2009 18:44
Show Gist options
  • Save marciobarrios/220694 to your computer and use it in GitHub Desktop.
Save marciobarrios/220694 to your computer and use it in GitHub Desktop.
para autolimpiar inputs/textarea (podria hacer que con una clase se ejecutara automáticamente)
//plugin para aplicar en textarea/inputs para que cuando tenga el foco se elimine el contenido
$.fn.autoClean = function() {
return this.filter('input, textarea').each(function(){
var $this = $(this);
$this
.attr('default',$this.val())
.focus(function(){
if ( $this.attr('id') == 'terms' ) {
if ($this.val() == $this.attr('title') ) $this.val('');
} else {
if ($this.val() == $this.attr('default') ) $this.val('');
}
})
.blur(function(){
if ($this.val() == '') $this.val($this.attr('default'));
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment