+ 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')";
1 ответ
+ 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 + ")"