[英]apply css rules on programmatically created div
I have a site that creates new divs in real time (using JS). 我有一个网站(使用JS)实时创建新的div。 The class of each div is "conv".
每个div的类均为“ conv”。 My problem is, that the css rules that I have written for this class doesn't apply to the new divs.
我的问题是,我为此类编写的css规则不适用于新的div。
conv.length
is the length of the xml file I am using. conv.length
是我正在使用的xml文件的长度。
The JS: JS:
for(i=0; i<conv.length;i++){
var div= document.createElement("div");
div.id="conv"+i;
div.class= "conv";
div.innerHTML=conv[i].childNodes[0].nodeValue;
div.style.height="50px";
div.style.overflow="hidden";
document.getElementById("conv").appendChild(div);
}
The CSS: CSS:
.conv {
background-color:#CCC;
}
The class
property of an HTML element is a special case, it is not the class
attribute. HTML元素的
class
属性是一种特殊情况,不是class
属性。 That one is accessible via className
: 可以通过
className
访问:
div.className="conv";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.