JS
JS Clone Project [Background]
Kai1996
2021. 12. 5. 22:19
- Image.js
//Saved Image source names
const images = [
"0.jpeg",
"1.jpeg",
"2.jpeg"
];
//choose random images
const chosenImage = images[Math.floor(Math.random() * images.length)];
//create <img> tag
const bgimage = document.createElement("img");
//add img src
bgimage.src = `img/${chosenImage}`;
console.log(bgimage);
//append img tag on the body
document.body.appendChild(bgimage);
- Key Points
1. createElement()
2. appendChild()