JSFiddle - React, Tailwind, and code Playground

by netnguyen270

HTML

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  <div class="vb-content">
    <h1>Single File Upload</h1>
    <input type="file" id="file-uploader">
    <p>Upload a file and see the output in browser console</p>
    <p id="feedback"></p>
  </div>
</body>
</html>

CSS

html {
  min-height: 100vh;
}

body {
  background: #000000;
  color: #FFFFFF;
}

.vb-content {
  display: flex;
  justify-content: center;
  flex-direction: column;
  align-items: center;
  font-family: 'Roboto Mono', monospace;
}

JavaScript

const fileUploader = document.getElementById('file-uploader');

fileUploader.addEventListener('change', (event) => {
  const files = event.target.files;
  console.log('files', files);
  
  const feedback = document.getElementById('feedback');
  const msg = `File ${files[0].name} uploaded successfully!`;
  feedback.innerHTML = msg;
});