4
I am using a preview script for images created with jquery, but I want to perform it in Javascript Vanilla, I am looking for a way to replace the variable command All.Empty(); however I could not find, how to replace this command ?
Code in Jquery
$("#fileUpload").on('change', function () {
if (typeof (FileReader) != "undefined") {
var image_holder = $("#image-holder");
image_holder.empty();
var reader = new FileReader();
reader.onload = function (e) {
$("<img />", {
"src": e.target.result,
"class": "thumb-image"
}).appendTo(image_holder);
}
image_holder.show();
reader.readAsDataURL($(this)[0].files[0]);
} else{
alert("Este navegador não suporta FileReader.");
}
});
You want to replace the command Empty(); of jquery with the native js is this?
– Miguel
exact bro :D want to know how it works in vanilla
– Murilo Melo
I think that
ele.innerHTML = '';
resolves– Miguel
for an input of type file ? for example file.innerHTML = null ?
– Murilo Melo
You want to take the selected file out of the input file is that?
inputfile.value='';
– Miguel
So, I’m not sure what logic was used by the guy, but I’ll update the question with the code in jquery
– Murilo Melo
The function
empty
jQuery excludes all child elements from the selected element. In this case, it would exclude all child elementsimg
within the element#image-holder
. In the vanilla, the equivalent would be something likedocument.getElementById("image-holder").innerHTML = ''
, just like Miguel said.– Woss
thanks, someone could formulate a reply to give as conclusion ?
– Murilo Melo