-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
28 lines (24 loc) · 994 Bytes
/
Copy pathscript.js
File metadata and controls
28 lines (24 loc) · 994 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
document.addEventListener("DOMContentLoaded", () => {
const uploadBtn = document.getElementById("uploadBtn");
const imageUpload = document.getElementById("imageUpload");
const previewContainer = document.getElementById("previewContainer");
// Open file input when upload button is clicked
uploadBtn.addEventListener("click", () => {
imageUpload.click();
});
// Handle file selection and preview
imageUpload.addEventListener("change", (event) => {
previewContainer.innerHTML = ""; // Clear previous previews
const files = event.target.files;
if (files.length === 0) return;
for (const file of files) {
const reader = new FileReader();
reader.onload = function(e) {
const img = document.createElement("img");
img.src = e.target.result;
previewContainer.appendChild(img);
};
reader.readAsDataURL(file);
}
});
});