Skip to content

Instantly share code, notes, and snippets.

@alexeckermann
Created July 4, 2011 02:54
Show Gist options
  • Save alexeckermann/1062840 to your computer and use it in GitHub Desktop.
Save alexeckermann/1062840 to your computer and use it in GitHub Desktop.
Custom file input style
jQuery.fn.customfile = function(opts){
var options = $.extend({ text: 'Upload file' }, opts),
wrapper = $('<div />').addClass('jq-link-file-field-wrapper'),
hitarea = $('<div />').addClass('jq-link-file-field-hitarea'),
link = $('<a />').attr({'class': 'jq-link-file-field-link', href: 'javascript:void(0);'}).html(options['text']);
this.after(wrapper.append(hitarea.append(link)));
wrapper.css('position', 'relative').prepend(this);
this.css({opacity: 0.0, 'z-index': 100}); hitarea.css({'z-index': 10});
$([this[0], hitarea[0]]).css({position: 'absolute', left: 0, top: 0, display: 'block'});
$([wrapper[0], this[0]]).width(link.outerWidth()).height(link.outerHeight());
};
/*
$('#myinput').customfile({text: 'This hack sucks...'});
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment