I am currently creating an image gallery to work on my skills.
I have an array that consists of images that I have from a folder called 'images'.
I have an image that has an id of 'imgsrc' with an empty source on my HTML page, so it's not displaying anything. I would like to be able to have access to the first image in my 'images' folder and display it as the source for my image using Javascript.
Here is what I tried to do:
var images = ['images/1.jpg', 'images/2.jpg', 'images/3.jpg', 'images/4.jpg', 'images/5.jpg', 'images/6.jpg','images/7.jpg', 'images/8.jpg', 'images/9.jpg'];
var imgsrc = document.getElementById('imgsrc').src;
var index = 0;
imgsrc = images[index];
Here is my HTML :
<section class="gallery">
<img id='imgsrc' src="">
</section>
What should I do ?
I appreciate all responses
"/images/myimage.jpg"