0

document.getElementById("Id1").style.backgroundImage = "url(value)";

to change the background image attribute in the CSS. But, the attribute used in CSS is

background-Image

Why we can't use the same name under Javascript as document.getElementById("Id1").style.background-Image = "url(value)";

Community
  • 1
  • 1

1 Answers1

2

As @Bitwise Creative said, you can't use - out of string. Instead you can do this,

document.getElementById("Id1").style["background-image"] = "url(value)";

If you use document.getElementById("Id1").style.background-Image = "url(value)", what will happen means javascript consider as statement before '-' "document.getElementById("Id1").style.background" and image consider as variable. So you will get syntax error