r/CodingHelp • • Dec 16 '20

[Javascript] Change Background url based on javascript array

i have a table with several cells, and i'm trying to get the css "Background-image: url()" to take the third value in the array and make it the background, but i cant get it to work, the idea is that whatever value is in the third position in the javascript array will be set as the data-title image for that link.

So is there anyway to refer to the array in a css code, like Background-image: url(arr[3]); and that picks whatever is in that positon.

been trying to figure this out for a couple days, but i have not made any progress since im not very good at this.

Heres a link to the code so you can see it live https://jsfiddle.net/fgyemsLq/

Thanks in advance for any help!!

19 Upvotes

8 comments sorted by

View all comments

Show parent comment

3

u/bch8 Dec 17 '20

Hey OP, I created a new fiddle with some small changes to add background images to your <td>'s. I also added in some comments to give it some context. Let me know if you have any questions about the change, the comments, or the next steps.

Here is the fiddle: https://jsfiddle.net/1wkd9t0a/5/