I create elements with the var l = document.createElement("label");
and I assign its attributes with l.setAttribute("formControlName","e");
.
The problem is that the setAttribute method puts the formControlName in lowercase letters as you can see in the image below. I work with ionic so the capital letters are needed. Does anyone see what I did wrong?
Element.setAttribute() Sets the value of an attribute on the specified element. If the attribute already exists, the value is updated; otherwise a new attribute is added with the specified name and value.
Using setAttribute If the attribute is already assigned to an element, the value is overwritten. If not, elements are assigned a new attribute with indicated values and name.
The "setAttribute is not a function" error occurs for multiple reasons: calling the setAttribute() method on a value that is not a DOM element. placing the JS script tag above the code that declares the DOM elements. calling the setAttribute method on a jQuery object (should use attr() instead).
Use this instead:
l.setAttributeNS(null, "formControlName","e");
'setAttributeNS()' doesn't convert the name to lower case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With