Skip to content

Instantly share code, notes, and snippets.

@colourgarden
Created October 1, 2012 03:33
Show Gist options
  • Save colourgarden/3809338 to your computer and use it in GitHub Desktop.
Save colourgarden/3809338 to your computer and use it in GitHub Desktop.
Quick and dirty removal of browse button from file inputs
<div class="file-input">
<input type="file">
</div>
// Add ape input to DOM and hide file input
$('.file-input input[type="file"]').css({'visibility': 'hidden', 'height': 0}).append('<input type="text">');
// When the ape input is clicked, trigger a click on the file input and launch browse window
$('.file-input input[type="text"]').on('click', function(){
$(this).next('input[type="file"]').trigger('click');
});
// When the file input value changes, update the ape input too
$('.file-input input[type="file"]').on('change', function(){
var filename = $(this).val();
$(this).prev('input[type="text"]').val(filename);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment