Multiple image sources in one image element

I’m quite new to Javascript (no jquery pls) and I’m trying to figure out if I can put multiple image sources in one image element

sadImages = document.createElement("img");
sadImages.src = "video/sadness/sadPhoto1.png";
sadImages.className = "projectImages";

I would like to add a few more images from the sadness folder (not all!) without creating too many image elements.

I’ve tried writing it like

sadImages.src = "video/sadness/sadPhoto1.png" + "video/sadness/sadPhoto2.png";


sadImages.src = "video/sadness/sadPhoto1.png","video/sadness/sadPhoto2.png";


sadImages.src = ["video/sadness/sadPhoto1.png","video/sadness/sadPhoto2.png"];

but that doesn’t work. It might be really stupid, but I’m trying to keep my code as short as possible.

2 thoughts on “Multiple image sources in one image element”

Leave a Comment