Skip to content

Instantly share code, notes, and snippets.

@kaiohken1982
Forked from egm0121/jquery-clearform.css
Created November 14, 2011 16:07
Show Gist options
  • Save kaiohken1982/1364295 to your computer and use it in GitHub Desktop.
Save kaiohken1982/1364295 to your computer and use it in GitHub Desktop.
Clear Form JS jQuery Plugin
.clearform{
display:inline-block;
margin-left:-16px;
cursor:pointer;
width:10px;
height:10px;
background-image:url('/close.gif');
-webkit-box-shadow: 0px 0px 10px 5px #fff ;
}
.clearform:hover{
background-position:10px;
}
;(function( $ ){
var methods = {
init : function( options ) {
return this.each(function(){
if(!$(this).data('clearform')){
var btn = $('<span>'),
that = $(this);
that.data('clearform',true);
btn.addClass('clearform').attr('title','erase').click(function(){
$(that).attr('value','');
});
$(btn).insertAfter($(this));
}
});
},
destroy : function( ) {
return this.each(function(){
$(this).removeData('clearform').parent().find('.clearform').remove();
})
}
};
$.fn.clearform = function( method ) {
if (method in methods) {
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( (typeof method === 'object' || ! method) ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.clearform' );
}
};
})( jQuery );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment