I am using Firefox and I wanted to add dynamically created input
to the document. I use the dot notation to set attributes.
var input = document.createElement("input");
input.placeholder = "Working";
input.maxlength = 4;
document.getElementById("add_here").appendChild(input)
However, I encountered a strange issue.
The placeholder
attribute is correctly added, but the maxlength
is not set.
I made a JSFiddle to prove it: https://jsfiddle.net/phc8fxba/
The only workaround I found is to use .setAttribute(maxlength, 4)
but this is weird.
Why is dot notation not working here?
You have a typo, it should be:
input.maxLength = 4;