Here i have code for taking info about attached files:
<ul id="result"></ul>
<script>
var elem = document.getElementById('upload-field');
elem.addEventListener('change', getFileData);
function getFileData() {
const files = this.files;
const list = document.getElementById("result");
let child;
for ( let i = 0; i < files.length; i++) {
child = document.createElement("li")
child.textContent = files[i].name;
list.append(child);
}
}
</script>
but when I click on the button and attach the file - it shows this file info.
When I do it again code added this file info again under the previous text, and I would like to "reset" the list of files when I attach files again, but I don't know how to improve this code :(