Skip to content

Instantly share code, notes, and snippets.

@wireinet
Created August 20, 2019 07:53
Show Gist options
  • Save wireinet/1a5d51466e049e3ce1728298e3f085e5 to your computer and use it in GitHub Desktop.
Save wireinet/1a5d51466e049e3ce1728298e3f085e5 to your computer and use it in GitHub Desktop.
// attach file
(function() {
'use strict';
$('.input-file').each(function() {
var $input = $(this),
$label = $input.next('.js-labelFile'),
labelVal = $label.html();
$input.on('change', function(element) {
var fileName = '';
if (element.target.value) fileName = element.target.value.split('\\').pop();
fileName ? $label.addClass('has-file').find('.js-fileName').html(fileName) : $label.removeClass('has-file').html(labelVal);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment