challenge-tourist-attractio.../js.js

41 lines
1.0 KiB
JavaScript
Raw Normal View History

2022-11-16 23:04:45 +00:00
document.addEventListener('DOMContentLoaded', function () {
const inputFile = document.querySelector('#input__img');
const labelInput = document.querySelector('.label-input');
const textLabelInput = "Imagem";
labelInput.innerHTML = textLabelInput;
inputFile.addEventListener('change', (e) => {
const inputTarget = e.target;
const file = inputTarget.files[0];
if (file) {
const reader = new FileReader();
reader.addEventListener('load', (e) => {
const readerTarget = e.target;
const img = document.createElement('img');
img.src = readerTarget.result;
img.classList.add('img-result');
labelInput.appendChild(img);
});
reader.readAsDataURL(file);
labelInput.innerHTML = "";
labelInput.style.border = "none";
}else {
labelInput.innerHTML = textLabelInput;
}
});
2022-11-16 23:04:45 +00:00
});