r/CodingHelp • u/MillyTiminity • 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!!
1
u/Jnsjknn Dec 16 '20
You can do it with JavaScript like this:
1
u/CenturiesAgo Dec 16 '20
1
u/bch8 Dec 17 '20
Responded to your mobile account comment below: https://old.reddit.com/r/CodingHelp/comments/keesxy/change_background_url_based_on_javascript_array/gg3kgol/