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)";
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.