Hello
is it possible to set an src
attribute inside an object value for an image ,
I’ve managed and done this with setAttribute ()
but what I want when I iterate on an object to set different Images I hope that clear.
this is my codepen
Have you tried it yet? Why not just set the img
property for each object in movies
to the URL you want to use and then give it a try?
hey @bbsmooth actually I’ve tried img: url("https://cdn.europosters.eu/image/1300/posters/batman-dark-knight-joker-i13945.jpg")
but it did not work
This is CSS. I thought you wanted to do this with JS? Look at your current code. You are already setting the src
attribute on the image, you just have the URL for the image hardcoded in the code. You need to instead set the image URL for each object in the movies
array and then use that to set the src
attribute on the image as you go through each object in the array.
Thanks a lot @bbsmooth now it’s working as you said I’ve set a URL link for each img key then in the setAttribute("src" , movies[i].img)
You could also just write:
img.src = movies[i].img;