Preview input field does not work

1

My browser is not displaying the image. Something wrong with this code?

$(document).ready(function ()
{
     $("input[name='fun_imagem']").change(function ()
     {
         readImage($(this));
     });

});


function readImage(input) {

     var arquivo = new FileReader();
     arquivo.onload = function(e)
     {
          $("#imagem-figure-usuario").attr("src", e.target.result);
     };

     arquivo.readAsDataURL(input.files[0]);
}
    
asked by anonymous 02.09.2016 / 22:54

1 answer

1

I noticed that you are passing a list of jQuery elements to the readImage function.

readImage($(this));

You just have to stop covering this with $ jQuery. If you did not notice, this is a single HTML element, the element in the $("input[name='fun_imagem']") list that was clicked. The jQuery prototype does not provide a files property, nor a function. Then:

readImage(this);

If it was already in a jQuery list (in other cases) you would only need to index with a specific index, for example: $ls[0] , would return the first element in the list.

    
03.09.2016 / 00:11