0

I have a site that creates new divs in real time (using JS). The class of each div is "conv". My problem is, that the css rules that I have written for this class doesn't apply to the new divs. conv.length is the length of the xml file I am using.

The 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:

.conv {
  background-color:#CCC;
}

1 Answer 1

5

The class property of an HTML element is a special case, it is not the class attribute. That one is accessible via className:

div.className="conv";
Sign up to request clarification or add additional context in comments.

1 Comment

Well, I know it because I stumbled on the same issue a few years ago :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.