author: Krasimir Tsonev

Hi there, I'm . Senior front-end engineer with over 13 years of experience. I write, speak and occasionally code stuff. Follow me on Twitter, GitHub, Facebook or LinkedIn

CSS styles doesn\'t work on dynamically created elements in IE

Again, IE proves that is full with bugs. Simple but effective solution.
If you have the following code:
var element = document.createElement("div");
element.setAttribute("class", "yourClassName");
change it to:
var element = document.createElement("div");
element.className = "yourClassName";
.className property also works in FF, Opera and Safari.
If you enjoy this post, share it on Twitter, Facebook or LinkedIn. Or maybe comment below: