I can’t do something like this:
var div1 = document.createElement("div"); div1.class = "one";
Instead, you need to do this:
div1.className = "one";
“className” is a subtle alternative that will apply the “class” attribute to any HTML element.
Side-note: I don’t quite understand why it’s called “className,” when “classAttributeValue,” or “classValue” would make more sense.
element. For example:
var label1 = document.createElement("label"); label1.for = "one";
I bet you’re guessing we need to use
Instead, we can try something like this:
var label1 = document.createElement("label"); label1.setAttribute("for", "one");
This seems to work fine in most standards-aware browsers, but Internet Explorer 8 does not seem to support it, so at the moment it’s not a universal solution.
If anyone has another work-around for this, please help resolve this “pain.”