I'm currently creating an online quiz with HTML, JS, & CSS.
I have created question boxes that cycle through each question, but I am trying to have a different image displayed for each new question.
I currently have a CSS element that can place an image into the quiz box but doing that means I have the same image for every question.
I was hoping to use JS to change the image but I haven't quite got it yet.
.styledimg {
background-image: url(spider.png);
background-repeat: no-repeat;
width: 640px;
height: 360px;
}
Here I have the image contained in the CSS element
let questions = [
{
numb: 1,
question: "Question",
answer: "option",
options: [
"option",
"option",
"option",
"option"
]
},
Here is the start of the array that houses my questions
<div class="styledimg"></div>
Here is the tag associated with the CSS element
I was trying to use something like 'document.querySelector("styledimg").style.background-image = "clock.png"'
to change the image for each question but to no avail.
If anyone could point me in the right direction that would be appreciated.