E
E
Edgar Balyan2021-07-04 20:02:14
css
Edgar Balyan, 2021-07-04 20:02:14

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

1 answer(s)
E
Evgeny Golubev, 2021-07-07
@bestowhope

one.

script.js is located in the js folder.

TSYA Mlyat
2:
when I translate this code into css it works but for some reason it doesn't

Why are you trying to turn CSS into JS? You don't make sugar out of water...
3:
element.style.backgroundImage = "url('your cdn path')";

or
var div = document.querySelector(...); // select the div
div.style.backgroundImage = "url('" + urlString + "')";

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question