Created
October 1, 2012 03:33
-
-
Save colourgarden/3809338 to your computer and use it in GitHub Desktop.
Quick and dirty removal of browse button from file inputs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="file-input"> | |
<input type="file"> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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