Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setAttribute makes the attribute name lowercase

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?

enter image description here

enter image description here

like image 478
BrianM Avatar asked Jan 17 '18 11:01

BrianM


People also ask

What does setAttribute do in JavaScript?

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.

Does setAttribute overwrite?

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.

Why is setAttribute not working?

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).


1 Answers

Use this instead:

l.setAttributeNS(null, "formControlName","e");

'setAttributeNS()' doesn't convert the name to lower case.

like image 108
Chifti Saidi Avatar answered Oct 22 '22 11:10

Chifti Saidi