+ 3

why cannot the image appear in the web

var url="https://www.sololearn.com/Icons/Courses/1024.png"; document.getElementById("background").style.backgroundImage="url(url)"; //while this way can show up. document.getElementById("background").style.backgroundImage="url('https://www.sololearn.com/Icons/Courses/1024.png')";

9th May 2019, 7:19 AM
KunhongLee
KunhongLee - avatar
1 Réponse
+ 5
Because in the first thing you posted the string is just "url(url)" To replace the url with the actual value of the variable you have to do sometging like this: "url(" + url + ")"
9th May 2019, 7:22 AM
Dragonxiv
Dragonxiv - avatar