Answer the question
In order to leave comments, you need to log in
I want to write background-image css code in javascript but it doesn't work?
sym.style.background = "url('../img/O.png') center no-repeat"
script.js is in the js folder.
I leave the folder and go to the img folder and write the name of the picture,
I want the picture to be in the middle and not repeat what I wrote.
when I translate this code into css it works but for some reason it doesn't.
Answer the question
In order to leave comments, you need to log in
one.
script.js is located in the js folder.
when I translate this code into css it works but for some reason it doesn't
element.style.backgroundImage = "url('your cdn path')";
var div = document.querySelector(...); // select the div
div.style.backgroundImage = "url('" + urlString + "')";
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question