[英]Javascript change html or body css
I use in my webpage the css description 我在网页中使用CSS描述
body {
font-size: 12px;
font-family: Sans-Serif;
background: url(images/diffdummy.png) no-repeat center center fixed;
overflow: hidden;
display: block;
margin-left: auto;
margin-right: auto;
}
How I can remove the background image with java script on runtime? 如何在运行时使用Java脚本删除背景图像? I tried
我试过了
document.getElementById("html").style.background="";
document.getElementsByTagName("html").style.background="";
document.getElementsByTagName("html")[0].style.background="";
But nothing is working. 但是没有任何效果。 Anybody here who can give me a hint?
有人可以给我提示吗?
Why html
when you are using body
as your CSS selector? 在将
body
用作CSS选择器时为什么使用html
?
just use: 只需使用:
document.getElementsByTagName('body')[0].style.background = "none";
or 要么
document.body.style.background = "none";
Code in action! 实际代码!
// removing background-color from body document.getElementsByTagName('body')[0].style.background = "none";
body { height: 100px; width: 100%; background-color: red; } div { height: 40px; width: 20%; background-color: green; }
<body> <div></div> </body>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.