<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Newsletter</title>
<link rel="stylesheet" href="style.css">
<script src="app.js" defer></script>
</head>
<body>
<div>
<h1>Image Upload(jpg,jpeg, and png)</h1>
<input type="file" id="file-uploader" accept=".jpg, .jpeg, .png" >
<div id="image-grid">
</div>
</div>
</body>
</html>
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
height: 100%;
}
body {
background: white;
color: black;
height: 100vh;
}
div {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
align-items: center;
font-family: 'Roboto Mono', monospace;
margin-top: 20px;
}
input{
margin-top: 20px;
}
const fileUploader = document.getElementById('file-uploader');
const reader = new FileReader();
const imageGrid = document.getElementById('image-grid');
fileUploader.addEventListener('change', (event) => {
const files = event.target.files;
const file = files[0];
reader.readAsDataURL(file);
reader.addEventListener('load', (event) => {
const img = document.createElement('img');
imageGrid.appendChild(img);
img.src = event.target.result;
img.alt = file.name;
});
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.