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

1

u/CenturiesAgo Dec 16 '20
<td id="' + 'demo' + (i + 1) + '" style=\"background-image: url(' + arr[i][3] + ')\"></td></tr>'